PartyServer ships two routing utilities that bridge incoming Worker requests to namedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/partykit/llms.txt
Use this file to discover all available pages before exploring further.
Server Durable Objects. routePartykitRequest handles URL-based routing for both WebSocket and HTTP requests following the /:prefix/:party/:name convention. getServerByName lets you obtain a Durable Object stub directly by name when you want to address a server from within your own routing logic.
routePartykitRequest
Request against the URL pattern /${prefix}/:party/:name and forward it to the matching Durable Object namespace. Returns null when the URL does not match, so you can chain it with your own fallback handler.
Namespace matching is case-insensitive and kebab-case aware: a binding named MyServer in wrangler.jsonc is matched by the URL segment my-server.
A
Response when the URL matched a known namespace and the request was forwarded, or null when no match was found. Also returns a 400 Bad Request response when the URL matches the prefix pattern but references an unknown namespace.Options
The URL path prefix to match. Requests must start with
/${prefix}/:party/:name. Supports multi-segment prefixes like "api/rooms".Preferred location hint for where the Durable Object should be placed (e.g.
"wnam", "eeur"). Only applies to new objects — existing objects stay in their current location.Restrict the Durable Object to a specific jurisdiction for data residency compliance (e.g.
"eu").Arbitrary JSON-serializable properties to deliver to the server’s
onStart hook. Encoded in the x-partykit-props request header and decoded inside the DO.Enable CORS for matched routes.
Control retry behavior for transient Durable Object infrastructure errors. Enabled by default with 3 attempts and jittered exponential backoff. Pass
false to disable retries entirely. See RoutingRetryOptions.Intercept WebSocket upgrade requests before they reach the server. Called only for requests with an
Upgrade: websocket header.Intercept plain HTTP requests before they reach the server’s
onRequest handler. Behaves identically to onBeforeConnect but fires for non-WebSocket requests.The Lobby object
Both onBeforeConnect and onBeforeRequest receive a lobby argument:
The original Durable Object binding name as declared in
wrangler.jsonc (e.g. "MyServer").The server instance name extracted from the URL (the
:name segment).getServerByName
Server Durable Object without going through URL routing. Returns a DurableObjectStub you can call fetch() or RPC methods on. Before returning, getServerByName performs an RPC that awaits the server’s onStart() hook, so you can immediately invoke user-defined RPC methods on the stub and trust that initialization has completed.
The Durable Object namespace binding from your
env. Must correspond to a class that extends Server.The logical name of the server instance. Used as the Durable Object ID name.
Preferred geographic location for the Durable Object. Only affects placement of new objects.
Data residency jurisdiction restriction (e.g.
"eu").Initial properties passed to the server’s
onStart hook on first wake.Retry options for transient infrastructure errors. See RoutingRetryOptions. Pass
false to disable retries.A stub pointing to the named Durable Object, after
onStart() has completed.RoutingRetryOptions
Both routePartykitRequest and getServerByName support automatic retries for transient Durable Object infrastructure errors. Only errors with retryable === true are retried. Errors with overloaded === true are never retried regardless of other settings.
Maximum number of attempts, including the first try. Must be an integer ≥ 1.
Base delay in milliseconds for exponential backoff. Each retry waits a random duration up to
min(maxDelayMs, baseDelayMs × 2^(attempt-1)). Must be > 0.Upper cap in milliseconds for the jittered backoff delay. Must be ≥
baseDelayMs.Optional callback invoked before each retry delay. Useful for logging or metrics.