Type of an individual query parameter.
Object containing the query parameters accepted by an endpoint.
Create a DELETE endpoint definition.
Use of the template literal allows to easily add dynamic path parameters to the endpoint definition, as shown in the example below.
Use as a tagged template literal to add path parameters to the endpoint, and use methods of the EndpointBuilder class to customize the endpoint definition.
This endpoint definition can be consumed by API servers and clients such as rest-ts-express and rest-ts-axios.
Example:
export const commentsAPI = defineAPI({
// Remove a comment
// For example: DELETE /comments/123
removeComment: DELETE `/comments/${'id'}`
.response(CommentDeleteResponse)
});
Create a GET endpoint definition.
Use of the template literal allows to easily add dynamic path parameters to the endpoint definition, as shown in the example below.
Use as a tagged template literal to add path parameters to the endpoint, and use methods of the EndpointBuilder class to customize the endpoint definition.
This endpoint definition can be consumed by API servers and clients such as rest-ts-express and rest-ts-axios.
Example:
export const carsAPI = defineAPI({
// Get emissions test results for a given car.
// For example: GET /cars/VW_Golf_TDI/results => "OK"
getCarTestResults: GET `/cars/${'model'}/results`
.response(CarTestResults)
});
Create a PATCH endpoint definition.
Use of the template literal allows to easily add dynamic path parameters to the endpoint definition, as shown in the example below.
Use as a tagged template literal to add path parameters to the endpoint, and use methods of the EndpointBuilder class to customize the endpoint definition.
This endpoint definition can be consumed by API servers and clients such as rest-ts-express and rest-ts-axios.
Example:
export const commentsAPI = defineAPI({
// Edit a comment
// For example: PATCH /article/123/comment/2
editComment: PATCH `/article/${'id'}/comment/${'commentId'}`
.body(CommentAttributes)
.response(CommentSaveResponse)
});
Create a POST endpoint definition.
Use of the template literal allows to easily add dynamic path parameters to the endpoint definition, as shown in the example below.
Use as a tagged template literal to add path parameters to the endpoint, and use methods of the EndpointBuilder class to customize the endpoint definition.
This endpoint definition can be consumed by API servers and clients such as rest-ts-express and rest-ts-axios.
Example:
export const commentsAPI = defineAPI({
// Add a comment to an article
// For example: POST /article/123/comment
addComment: POST `/article/${'id'}/comment`
.body(CommentAttributes)
.response(CommentSaveResponse)
});
Create a PUT endpoint definition.
Use of the template literal allows to easily add dynamic path parameters to the endpoint definition, as shown in the example below.
Use as a tagged template literal to add path parameters to the endpoint, and use methods of the EndpointBuilder class to customize the endpoint definition.
This endpoint definition can be consumed by API servers and clients such as rest-ts-express and rest-ts-axios.
Example:
export const carsAPI = defineAPI({
// Edit a car in the list
// For example: PUT /cars/123/edit
editCar: PUT `/cars/${'id'}/edit`
.body(CarAttributes)
.response(CarSaveResponse)
});
Create an API definition to share across producers and consumers of the API.
The usual workflow of rest-ts-core goes like this:
Create an API definition:
const myAwesomeAPI = defineAPI({
someEndpoint: GET `/some/path`
.response(SomeResponseDTO)
});
Create a server for this API. rest-ts-express allows you to import the API definition you just created and turn it into an express router. See the documentation for that package for more details.
Create a consumer for this API. rest-ts-axios lets you create a typed instance of axios to perform requests to your API.
... Profit!
Notice: Unless you are authoring an adapter for Rest.ts, you should always treat the return type of this function
as an opaque type. Use the utilities provided by this library to create the API definition within the brackets
of defineAPI({ ... })
, and export the resulting symbol to be consumed by your server and client(s).
The type you get from defineAPI
is very complex, and for a good reason: it encodes all of the type information
of your API! It is pointless to inspect the raw type you get. Instead, we recommend that you feed it directly
to a compatible binding library such as rest-ts-express and rest-ts-axios. These libraries are able to decode
the complex type and make sense out of it.
Generated using TypeDoc
List of the supported HTTP methods.
If you think something is missing here, feel free to open a pull request.