Reference

rouzer/http

import { RoutePattern } from '@remix-run/route-pattern';

Functions

delete

Declare a DELETE action, optionally with an action-local path segment.

export function delete<const P extends string, const T extends RouteSchema>(path: P, schema: T): HttpAction<P, T, 'DELETE'>;
export function delete<const T extends RouteSchema>(schema: T): HttpAction<'', T, 'DELETE'>;

šŸ” delete on GitHub

get

Declare a GET action, optionally with an action-local path segment.

export function get<const P extends string, const T extends RouteSchema>(path: P, schema: T): HttpAction<P, T, 'GET'>;
export function get<const T extends RouteSchema>(schema: T): HttpAction<'', T, 'GET'>;

šŸ” get on GitHub

isRawBodySchema

export function isRawBodySchema(schema: unknown): schema is RawBodySchema;

šŸ” isRawBodySchema on GitHub

patch

Declare a PATCH action, optionally with an action-local path segment.

export function patch<const P extends string, const T extends RouteSchema>(path: P, schema: T): HttpAction<P, T, 'PATCH'>;
export function patch<const T extends RouteSchema>(schema: T): HttpAction<'', T, 'PATCH'>;

šŸ” patch on GitHub

post

Declare a POST action, optionally with an action-local path segment.

export function post<const P extends string, const T extends RouteSchema>(path: P, schema: T): HttpAction<P, T, 'POST'>;
export function post<const T extends RouteSchema>(schema: T): HttpAction<'', T, 'POST'>;

šŸ” post on GitHub

put

Declare a PUT action, optionally with an action-local path segment.

export function put<const P extends string, const T extends RouteSchema>(path: P, schema: T): HttpAction<P, T, 'PUT'>;
export function put<const T extends RouteSchema>(schema: T): HttpAction<'', T, 'PUT'>;

šŸ” put on GitHub

rawBody

Declare a request body that is passed through to fetch without JSON encoding.

export function rawBody(): RawBodySchema;

Remarks

For routes with path or query input, pass the body as options.body. For raw-body routes without input, generated client actions accept the body as their first argument.

šŸ” rawBody on GitHub

resource

Declare an HTTP resource namespace.

export function resource<const P extends string, const TChildren extends HttpRouteTree>(path: P, children: TChildren): HttpResource<P, StringKeys<TChildren>>;

Remarks

The resource path is joined with any parent resource path. Child property names are API names only; they do not affect the URL unless the child is another resource or an action with an explicit path.

šŸ” resource on GitHub

Types

HttpAction

Callable endpoint leaf in an HTTP route tree.

export type HttpAction<P extends string = string, T extends RouteSchema = RouteSchema, M extends HttpMethod = HttpMethod> = {
    kind: 'action';
    path?: RoutePattern<P>;
    method: M;
    schema: T;
    metadata?: RouteMetadata;
};

Remarks

Actions declare one HTTP operation. Their property name becomes the client/handler name, while their optional path contributes URL segments.

Properties

  • kind Discriminator used internally when traversing route trees.

  • path Optional action-local path segment appended after parent resources.

  • method HTTP method used when the client sends this action.

  • schema Request validation and optional response type schema.

  • metadata Optional runtime metadata for generated tooling.

šŸ” HttpAction on GitHub

HttpMethod

HTTP methods supported by Rouzer action declarations.

export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';

šŸ” HttpMethod on GitHub

HttpNode

Node type accepted inside an HTTP route tree.

export type HttpNode = HttpAction | HttpResource;

šŸ” HttpNode on GitHub

HttpResource

Path-scoped namespace in an HTTP route tree.

export type HttpResource<P extends string = string, TChildren extends HttpRouteTree = HttpRouteTree> = {
    kind: 'resource';
    path: RoutePattern<P>;
    children: TChildren;
    metadata?: RouteMetadata;
};

Remarks

Resources contribute URL path segments and contain child resources or actions. They do not have handlers of their own.

Properties

  • kind Discriminator used internally when traversing route trees.

  • path Path segment contributed by this resource.

  • children Child resources and actions exposed below this resource.

  • metadata Optional runtime metadata for generated tooling.

šŸ” HttpResource on GitHub

HttpRouteTree

Route tree accepted by HTTP clients and routers.

export type HttpRouteTree = {
    [key: string]: HttpNode;
};

šŸ” HttpRouteTree on GitHub

StringKeys

type StringKeys<T> = Pick<T, Extract<keyof T, string>>;

šŸ” StringKeys on GitHub