Request Event
Read SvelteKit request context from a SER remote handler.A remote function begins with decoded input, although the request often carries context of its own. A session cookie may identify the caller, while locals may contain data prepared by a server hook.
SER exposes the current SvelteKit request as the RequestEvent effect service. Yield it inside a remote handler to read the request that triggered that call.
Read the current request
RequestEvent includes cookies, getClientAddress, locals, params, platform, request, route, and url.
import { Effect } from "effect";
import { Query, RequestEvent } from "svelte-effect-runtime";
export const GetSession = Query(
Effect.gen(function* () {
const event = yield* RequestEvent;
const session_id = event.cookies.get("session") ?? null;
return {
session_id,
path: event.url.pathname,
};
}),
);The value is the request for this invocation of GetSession(). Another request receives another service value, even though both handlers run through the same server runtime.
Change a cookie
The cookie API is SvelteKit's own. A command can delete the session cookie before it returns:
import { Effect } from "effect";
import { Command, RequestEvent } from "svelte-effect-runtime";
export const SignOut = Command(
Effect.gen(function* () {
const event = yield* RequestEvent;
event.cookies.delete("session", { path: "/" });
}),
);SvelteKit still applies its usual cookie rules, including an explicit path when deleting a cookie.
Read it from a helper
An effect called by the handler inherits the same request context. This keeps request access inside the effect graph without threading the event through every function argument.
import { Effect } from "effect";
import { RequestEvent } from "svelte-effect-runtime";
export const ReadSessionId = Effect.gen(function* () {
const event = yield* RequestEvent;
return event.cookies.get("session") ?? null;
});import { ReadSessionId } from "$lib/server/session";
import { Query } from "svelte-effect-runtime";
export const GetSessionId = Query(ReadSessionId);Request scope
SER installs the current RequestEvent value around each remote handler effect. Concurrent calls can share one ServerRuntime, yet each handler reads cookies and locals from its own request.
Outside a remote handler
Yielding RequestEvent during module initialization, runtime startup, or another effect without a remote request throws RequestEventUnavailableError.
That error means the effect was evaluated before SER installed request context. Move the yield* RequestEvent into the remote handler or an effect reached from that handler.