This site counts visits with analytics cookies only if you accept. Read the consent

Skip to content

AdvancedPath Parameters

Path Parameters

Dynamic URL segments with :param and {param}, a {+param} that keeps its slashes, filled from the variables or pathOptions, a colon sent as written for Google-style methods, and values a closure puts into its path.

10 min readUpdated both modes

Basic syntax

Use the :paramName syntax in URL paths to define dynamic segments. Courier fills each one with a value from the variables or from pathOptions, encoded into its segment:

api/users.ts
import { courier, defineGroup } from "@noverax/courier/define"

const { endpoint } = courier()

type User = { id: number; name: string }
type Comment = { id: number; body: string }

const users = defineGroup({
  prefix: "users",
  endpoints: {
    // GET /users/:id -> compiled to GET /users/5
    getById: endpoint.get(":id").variables<{ id: number }>().response<User>(),

    // GET /users/:userId/posts/:postId/comments/:commentId
    getComment: endpoint.get(":userId/posts/:postId/comments/:commentId").variables<{
      userId: number
      postId: number
      commentId: number
    }>().response<Comment>(),
  },
})

Typed parameters

An endpoint's variables follow its path. With none declared, the variables are the path's parameters, each one required. Variables declared before or after the path must name each of its parameters: one left out is a type error where the endpoint is written, not a failed request later.

api/articles.ts
import { courier, defineGroup } from "@noverax/courier/define"

const { endpoint } = courier()

type Article = { id: number; title: string }

export const articles = defineGroup({
  prefix: "articles",
  endpoints: {
    // variables: { id: string | number }
    getById: endpoint.get(":id").response<Article>(),
    update: endpoint.put(":id").variables<{ id: number; title: string }>().response<Article>(),
    // @ts-expect-error — the variables do not name :id
    getBySlug: endpoint.get(":id").variables<{ slug: string }>().response<Article>(),
  },
})

Variables that fill no parameter by name — a form, a raw body, a list — are not checked, and neither are the parameters of a group's prefix, which pathOptions may supply (see below). Variables that may be either are read member by member: in FormData | { bookId: string; title: string } the form fills :bookId from its own field, and the record names it, so both may be passed; a record in the union that leaves a parameter out is refused.

How a path is read

  • A parameter is a colon and a name: a letter or _, then letters, digits and _. The name ends at the first other character, so a parameter may share its segment with text or with another parameter: :id.json, flights/:from-:to.
  • A name in braces, {name}, is the same parameter with its end written, for one that text follows at once: files/{id}abc takes the id, and abc is text.
  • {+name} is a parameter whose value keeps its slashes: each part between them is encoded, and the slashes are sent as written. See A value with slashes.
  • Braces around anything but a name are sent as written, encoded as a URL encodes them.
  • A colon before anything else — a digit, a dash, the end of the path — is sent as written: at/12:30.
  • :: is one colon sent as written, even before a name. See the next section.
  • The scheme and host of an absolute URL are never read: a port or an IPv6 address, as in https://[2001:db8::1]:8443/users/:id, holds no parameter.
  • A query written into the path is sent as written, a :name or a :: in it too: items?sort=:field asks for no variable. A read's variables go to its query string themselves, beside the ones the path fixes.
  • A path that writes a fragment, items#top, is refused where the endpoint or the group declares it: a request sends its path up to the #, and the query a read's variables make would have gone after it. A literal path the endpoint itself is declared with, as in endpoint.get("items#top"), is refused by its type as well; a group's prefix and a closure's path are not. Write %23 for a # the path sends.

The types read a path the same way, so the variables an endpoint asks for are the parameters its requests fill.

How a value is written

A parameter's value is written as JSON writes it in the record a proxy call carries, its own toJSON asked first, so a direct call and a call through the proxy send the same path: a date is its ISO string, 2026-11-15T00%3A00%3A00.000Z once encoded, whatever time zone the machine is in. A list or an object is written in OpenAPI's style for a path, simple: a list as its items, an object as each field's name and value, with a comma between each two and each encoded on its own, so a comma inside one is sent as %2C:

Lists and objects
// GET /users/3,4%2C5
await caller.users.byIds({ ids: [3, "4,5"] })

// GET /reports/role,admin,page,2
await caller.reports.filtered({ filter: { role: "admin", page: 2 } })

A value JSON writes as null or leaves out — NaN, a date that is no date — has no text to send: the call is refused with an HTTPError 400 before a request is made, as it is for an empty list. A file, a Set, a Map or a BigInt is refused with a ConfigurationError whose code is VARIABLE_NOT_ENCODABLE, as it is in a query or a body. A stream's and a channel's parameters are written the same way, and the OpenAPI document gives each parameter the variable's own schema, which this style is OpenAPI's default for.

A colon the path sends as written

Google's APIs name a method on a resource after a colon — index:inspect, {name}:cancel, spreadsheets/{spreadsheetId}:batchUpdate — where a single colon before a word would start a parameter. Write the colon twice and it is sent once:

api/search-console.ts
import { courier, defineApi, defineGroup } from "@noverax/courier/define"

const { endpoint } = courier()

type Inspection = { inspectionResult: { indexStatusResult: { verdict: string } } }

const urlInspection = defineGroup({
  prefix: "v1/urlInspection",
  endpoints: {
    // POST /v1/urlInspection/index:inspect, its variables as the JSON body
    inspect: endpoint
      .post("index::inspect")
      .variables<{ inspectionUrl: string; siteUrl: string }>()
      .response<Inspection>(),
  },
})

export const searchConsole = defineApi({
  baseURL: "https://searchconsole.googleapis.com",
  groups: { urlInspection },
})

A parameter can stand right before such a colon, and the doubled colon is no parameter to the types:

Custom methods
const operations = defineGroup({
  prefix: "v1",
  endpoints: {
    // variables: { name: string | number } → POST /v1/op-1:cancel
    cancel: endpoint.post(":name::cancel").response<void>(),
    // POST /v1/sheet-1:batchUpdate, { requests } as the body
    batchUpdate: endpoint
      .post(":spreadsheetId::batchUpdate")
      .variables<{ spreadsheetId: string; requests: unknown[] }>()
      .response<void>(),
  },
})

Encoding the colon is no way around it: index%3Ainspect is another path, and Google's API does not answer it. Everything that reads the path reads :: the same way: an OpenAPI document gives the path with one colon, /v1/urlInspection/index:inspect; Studio's import doubles a colon a specification's path writes as text; and the mock server serves the endpoint where the client sends it.

A value with slashes

Google's APIs name a resource by its whole path — projects/p/locations/l/operations/o — and write it into a method's path as v1/{+name}. A :name parameter would send that value as one segment, its slashes encoded as %2F. Write the parameter {+name} and its slashes are sent as written, each part between them encoded:

api/operations.ts
const operations = defineGroup({
  prefix: "v1",
  endpoints: {
    // GET /v1/projects/p/locations/l/operations/o
    get: endpoint.get("{+name}").variables<{ name: string }>().response<Operation>(),
    // POST /v1/projects/p/locations/l/operations/o:cancel
    cancel: endpoint.post("{+name}::cancel").variables<{ name: string }>().response<void>(),
  },
})

Each part is encoded as a whole segment's value is, % and : included, so projects/a%2Fb/x:y is sent as projects/a%252Fb/x%3Ay: this is not RFC 6570's reserved expansion of {+var}, which sends a part's reserved characters and percent-escapes as written. A part that is empty, . or .. is refused, as such a whole value is for any parameter: projects/../admin would name another route. The OpenAPI document writes the parameter as {name} and says that it keeps its slashes; Studio's import keeps a specification's {+name}; the mock server answers the endpoint at every path its value can make; and an agent calling it through Courier MCP is told that the value may hold slashes.

A value in a closure's path

A closure that works its variables into its path writes them with http.path. Each value it puts in is text the request sends as it is, encoded, so that no value is read as a parameter, a colon, a query or a fragment; the text around the values is read as any path is, so :id and {+name} still name parameters there:

api/reports.ts
const reports = defineGroup({
  prefix: "reports",
  endpoints: {
    // GET /reports/2026-10/summary
    monthly: endpoint
      .variables<{ year: number; month: number }>()
      .via((http, { year, month }) => http.get(http.path`${year}-${month}/summary`, undefined)),
  },
})

A value interpolated into the path as plain text is read as part of the path: a name such as report:draft becomes a parameter named draft, filled from another variable when one has that name. A value put in with http.path is a segment's text, not one of the path's parameters, so the endpoint's variables are still sent unless the call says otherwise — undefined after the path sends none. A call refuses a value that is undefined or null, which would be sent as text, and one that makes its segment empty, . or .. — alone, or with the text and the values beside it, as ${name}.${ext} does with "." and "" — as it refuses such a parameter's value. A stream's and a channel's closures have the same path, as sse.path and ws.path.

Variables as path params

When you pass variables to a request, Courier first extracts any values that match path parameter names. The remaining variables are sent as query parameters (for GET/DELETE) or as the request body (for POST/PUT/PATCH):

Variable consumption
// Path params are extracted from the variables object.
// Remaining variables go to query params (GET) or body (POST).

const users = defineGroup({
  prefix: "users",
  endpoints: {
    getById: endpoint.get(":id").variables<{ id: number }>().response<User>(),
    getWithDetails: endpoint.get(":id").variables<{ id: number; include?: string }>().response<User>(),
    updateAvatar: endpoint.post(":id/avatar").variables<{ id: number; name: string }>().response<void>(),
  },
})

// GET /users/5 — { id: 5 } consumed by :id
await caller.users.getById({ id: 5 })

// GET /users/5?include=posts — { id: 5 } consumed by :id, { include: "posts" } -> query param
await caller.users.getWithDetails({ id: 5, include: "posts" })

// POST /users/5/avatar — { id: 5 } consumed by :id, { name: "photo.jpg" } -> JSON body
await caller.users.updateAvatar({ id: 5, name: "photo.jpg" })

Automatic extraction

You do not need to separate path params from body/query params manually. Courier handles this automatically based on the path definition. Just pass all variables in a single object.

pathOptions function

For path parameters that come from server-side context (cookies, headers, session) rather than the caller, use the pathOptions function. It runs on the server before every request and provides values for path compilation:

api/index.ts
import { courier, defineApi, defineGroup } from "@noverax/courier/define"

const { endpoint } = courier()

type User = { id: number; name: string }

const users = defineGroup({
  prefix: "orgs/:orgId/users",
  endpoints: {
    getAll: endpoint.get("").response<User[]>(),
    getById: endpoint.get(":id").variables<{ id: number }>().response<User>(),
  },
})

const api = defineApi({
  baseURL: process.env.API_URL,
  groups: { users },
  // pathOptions provides values for path params that come from context,
  // not from the caller's variables
  pathOptions: async (req) => {
    const cookieHeader = req?.headers.get("cookie") ?? ""
    const orgId = cookieHeader.match(/orgId=([^;]+)/)?.[1]
    return { orgId }
  },
})

// Now every request automatically includes :orgId from the cookie:
// GET /orgs/42/users       — orgId from pathOptions
// GET /orgs/42/users/5     — orgId from pathOptions, id from variables

Server-side only

The pathOptions function receives the Web Standard Request object and runs on the server inside the handler. It has access to cookies, headers, and any server-side context.

Group-level pathOptions

Each group can define its own pathOptions that override the source-level values for the same keys. This is useful when different groups resolve the same parameter differently:

api/groups.ts
import { courier, defineGroup } from "@noverax/courier/define"

const { endpoint } = courier()

type Project = { id: number; name: string }
type Task = { id: number; title: string }

const projects = defineGroup({
  prefix: "workspaces/:workspaceId/projects",
  // Group-level pathOptions override source-level pathOptions
  pathOptions: async (req) => {
    // For this group, workspaceId comes from a header
    const workspaceId = req?.headers.get("x-workspace-id")
    return { workspaceId }
  },
  endpoints: {
    getAll: endpoint.get("").response<Project[]>(),
    getById: endpoint.get(":id").variables<{ id: number }>().response<Project>(),
  },
})

const tasks = defineGroup({
  // No group pathOptions — uses the source-level pathOptions if any
  prefix: "tasks",
  endpoints: {
    getAll: endpoint.get("").response<Task[]>(),
  },
})

How variables flow

Understanding how variables are consumed is important. Here is the complete resolution order:

  1. Source-level pathOptions(request) is called
  2. Group-level pathOptions(request) is called (overrides source values)
  3. Caller's variables fill the path parameters pathOptions did not return
  4. Path parameters are extracted and consumed
  5. Remaining variables go to query params or body
typescript
// The flow of variables through path compilation:

// 1. pathOptions() is called -> returns { orgId: "42" }
// 2. variables from the caller fill the rest: { orgId: "42", id: 5, include: "posts" }
// 3. Path ":orgId/users/:id" consumes orgId and id
// 4. Remaining { include: "posts" } goes to query params (GET) or body (POST)
// 5. Final URL: GET /orgs/42/users/5?include=posts

// Group pathOptions override source pathOptions for the same key:
// Source pathOptions:  { orgId: "42" }
// Group pathOptions:   { orgId: "99" }
// Result:              { orgId: "99" }  <- group wins

The server's value always wins

A key pathOptions returns belongs to the server. A caller's variable of the same name is ignored and is not sent upstream, so a browser cannot name another tenant through the proxy. The key stays the server's when its value is undefined — a request without the session cookie is refused with a 400 instead of taking the caller's value.

To let the caller choose a path parameter, leave it out of pathOptions and declare it in the endpoint's variables.

Missing and unsafe path params

A path parameter that neither pathOptions nor the variables provide, or that is undefined or null, fails the call with an HTTPError 400 before any request is made. Its message, and data.message through the proxy too, name the parameter and where its value comes from: Missing required path parameter "id": pass it in the variables, or return it from pathOptions. So does a value of "", "." or "..": each would address a different route than the endpoint declares — .. one level up, even when encoded — so it is refused rather than sent, and for a {+name} so is any part between its slashes that is one of them. Any other value, including the word "undefined", is encoded into its segment as it is. A closure's path that holds a # when a call is addressed is refused the same way.

The check happens when the call is made, not when the endpoint is defined: the variables type may leave a parameter out on purpose, because pathOptions on the source or the group can fill it. A stream opened directly refuses a missing parameter the same way, with a RealtimeValidationError.

Next Steps