Options
All
  • Public
  • Public/Protected
  • All
Menu

External module rest-ts-core

Index

Type aliases

HttpMethod

HttpMethod: "GET" | "PUT" | "POST" | "DELETE" | "PATCH"

List of the supported HTTP methods.

If you think something is missing here, feel free to open a pull request.

QueryParamType

QueryParamType: rt.Runtype<any> | any

Type of an individual query parameter.

QueryParams

QueryParams: object

Object containing the query parameters accepted by an endpoint.

Type declaration

Functions

DELETE

GET

PATCH

POST

PUT

Const defineAPI

  • defineAPI<T>(api: T): T
  • Create an API definition to share across producers and consumers of the API.

    The usual workflow of rest-ts-core goes like this:

    1. Create an API definition:

       const myAwesomeAPI = defineAPI({
           someEndpoint: GET `/some/path`
               .response(SomeResponseDTO)
       });
    2. 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.

    3. Create a consumer for this API. rest-ts-axios lets you create a typed instance of axios to perform requests to your API.

    4. ... 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.

    Type parameters

    Parameters

    • api: T

    Returns T

Generated using TypeDoc