Webroute

@webroute/routeInterfaces

RouteBuilder

Type Parameters

Type Parameter
TParams extends RouteParams

Properties

PropertyTypeDescription
~defRouteDefInner<TParams>Internal

Methods

body()

body<$Parser>(schema): RouteBuilder<object>

Register a parser for the request body.

[Overrides]

Type Parameters

Type Parameter
$Parser extends Parser

Parameters

ParameterType
schema$Parser

Returns

RouteBuilder<object>

NameType
BodyInInferIn<$Parser>
BodyOutInfer<$Parser>
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

handle()

handle(handler): CompiledRoute<TParams>

Defines the request handler.

This concludes the route building process and produces a CompiledRoute instance.

Parameters

ParameterType
handlerHandlerFunction<TParams>

Returns

CompiledRoute<TParams>


headers()

headers<$Parser>(schema): RouteBuilder<object>

Register a parser for the request headers.

[Overrides]

Type Parameters

Type Parameter
$Parser extends Parser

Parameters

ParameterType
schema$Parser

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInInferIn<$Parser>
HeadersReqOutInfer<$Parser>
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

meta()

meta<TMeta>(meta?): RouteBuilder<object>

Add arbitrary metadata to the route.

This can act as an escape hatch for declaring information on routes that doesn't fit into existing webroute constructs.

Meta is shallow merged, so conflicting keys will override previous keys.

Use at your own discretion.

[Appends: Shallow Merge]

Type Parameters

Type Parameter
TMeta extends RouteMeta

Parameters

ParameterType
meta?TMeta

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTMeta
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

method()

method<TMethod>(method): RouteBuilder<object>

Set the route method(s).

[Overrides]

Type Parameters

Type Parameter
TMethod extends HttpMethodInput | HttpMethodInput[]

Parameters

ParameterType
methodTMethod

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTMethod extends HttpMethodInput ? Uppercase<TMethod<TMethod>> : Uppercase<TMethod[number]>
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

output()

output<$Parser>(schema): RouteBuilder<object>

Register a parser for the request output (response body).

[Overrides]

Type Parameters

Type Parameter
$Parser extends Parser

Parameters

ParameterType
schema$Parser

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInInferIn<$Parser>
OutputOutInfer<$Parser>
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

params()

params<$Parser>(schema): RouteBuilder<object>

Register a parser for the request path params.

[Overrides]

Type Parameters

Type Parameter
$Parser extends Parser

Parameters

ParameterType
schema$Parser

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInInferIn<$Parser>
ParamsOutInfer<$Parser>
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

path()

path<TPath>(path): RouteBuilder<object>

Set the route path.

If a path is already set upstream, this will append to the path.

[Appends]

Type Parameters

Type Parameter
TPath extends string

Parameters

ParameterType
pathTPath

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"] extends string ? `${any[any]}${TPath}` : TPath
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

provide()

provide<TProviders>(providers): RouteBuilder<object>

Registers providers which will get exposed to the handler under services.

[Appends: Shallow Merge]

Type Parameters

Type Parameter
TProviders extends AnyProviderMap

Parameters

ParameterType
providersTProviders

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
Providers{ [KeyType in string | number | symbol]: ({ [K in string | number | symbol]: K extends keyof TProviders ? TProviders[K<K>] : TParams["Providers"][K] } & TProviders)[KeyType] }
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
StateTParams["State"]

query()

query<$Parser>(schema): RouteBuilder<object>

Register a parser for the request query.

[Overrides]

Type Parameters

Type Parameter
$Parser extends Parser

Parameters

ParameterType
schema$Parser

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInInferIn<$Parser>
QueryOutInfer<$Parser>
StateTParams["State"]

use()

use<TMutations, TResult>(handler): RouteBuilder<object>

Register a route middleware.

Middleware may update the state context value. It may also return a Response early or register a request handler which will run on the egress journey.

State return values are shallow merged.

[Appends]

Type Parameters

Type ParameterDefault type
TMutations extends unknownunknown
TResult extends void | DataResultvoid

Parameters

ParameterType
handlerUseMiddlewareInput<TParams["ParamsOut"], TParams["QueryOut"], TParams["BodyOut"], TParams["HeadersReqOut"], TParams["State"], TParams["Providers"], void | TResult>

Returns

RouteBuilder<object>

NameType
BodyInTParams["BodyIn"]
BodyOutTParams["BodyOut"]
HeadersReqInTParams["HeadersReqIn"]
HeadersReqOutTParams["HeadersReqOut"]
InferredParamsTParams["InferredParams"]
MetaTParams["Meta"]
MethodsTParams["Methods"]
OutputInTParams["OutputIn"]
OutputOutTParams["OutputOut"]
ParamsInTParams["ParamsIn"]
ParamsOutTParams["ParamsOut"]
PathTParams["Path"]
ProvidersTParams["Providers"]
QueryInTParams["QueryIn"]
QueryOutTParams["QueryOut"]
Statevoid extends TResult ? TParams["State"] & TMutations : { [KeyType in string | number | symbol]: ({ [K in string | number | symbol]: K extends keyof TResult ? TResult[K<K>] : TParams["State"][K] } & TResult)[KeyType] }

On this page