Endpointclass

new Endpoint<P, R>(method: RequestMethod, path: AbsolutePath, payload: Schema<P>, result: Schema<R>)
ParamType
methodRequestMethod
The method of the endpoint, e.g. GET required
pathAbsolutePath
Endpoint path, possibly including placeholders e.g. /users/{id} required
payloadSchema<P>
A Schema for the payload of the endpoint. required
resultSchema<R>
A Schema for the result of the endpoint. required
Return
Endpoint<P, R>
A typed API resource definition pairing a method and path with payload and result schemas.
PropertyType
.methodRequestMethod
The HTTP method this endpoint responds to, e.g. GET required readonly
.pathAbsolutePath
Endpoint path, possibly including placeholders e.g. /users/{id} required readonly
.placeholdersTemplatePlaceholders
The {placeholder} segments extracted from path, used to render and match URLs. required readonly
.payloadSchema<P>
The Schema that request payloads are validated against. required readonly
.resultSchema<R>
The Schema that response results are validated against. required readonly

A typed API resource definition pairing a method and path with payload and result schemas.

  • Acts as the contract both ends of an API agree on: providers render requests from it, handlers validate against it.
  • Path may contain {placeholder} segments that are filled from the payload at request time.

Examples

const getUser = new Endpoint("GET", "/users/{id}", USER_PAYLOAD, USER_RESULT);

Methods

Go

Endpoint.renderPath()method

Render the path for this endpoint with the given payload.

renderPath(payload: P, caller: AnyCaller = this.renderPath): AbsolutePath
Go

Endpoint.match()method

Match a method/path pair against this endpoint and return any matched {placeholder} params.

match(method: RequestMethod, path: AbsolutePath, caller: AnyCaller = this.match): RequestParams | undefined
Go

Endpoint.handler()method

Create an endpoint handler pairing for this endpoint.

handler(callback: EndpointCallback<P, R, C>): EndpointHandler<P, R, C>
Go

Endpoint.toString()method

Convert this endpoint to a string in METHOD /path form, e.g. GET /user/{id}

toString(): string