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'>;
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'>;
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'>;
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'>;
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'>;
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.
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.
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
kindDiscriminator used internally when traversing route trees.pathOptional action-local path segment appended after parent resources.methodHTTP method used when the client sends this action.schemaRequest validation and optional response type schema.metadataOptional runtime metadata for generated tooling.
HttpMethod
HTTP methods supported by Rouzer action declarations.
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
HttpNode
Node type accepted inside an HTTP route tree.
export type HttpNode = HttpAction | HttpResource;
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
kindDiscriminator used internally when traversing route trees.pathPath segment contributed by this resource.childrenChild resources and actions exposed below this resource.metadataOptional runtime metadata for generated tooling.
HttpRouteTree
Route tree accepted by HTTP clients and routers.
export type HttpRouteTree = {
[key: string]: HttpNode;
};
StringKeys
type StringKeys<T> = Pick<T, Extract<keyof T, string>>;