Declaring endpoints
API.declareEndpoint(options) is the only way to declare an HTTP endpoint. This page is the map of what options can contain. The larger topics have their own pages; the smaller ones are covered here.
Method and URL
Every declaration needs a method and a url. The method is one of GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS. The URL is a path relative to the client's base URL, with $name marking URL parameters.
The options at a glance
A responseSchema is required unless the declaration has responses or a non-JSON response kind. Any key that is not in this table is a compile error, so a typo such as requstSchema cannot slip through. So are options that contradict each other, which also throw a NaviosError when the endpoint is declared:
responsestogether withresponseSchemaresponseSchemaorresponsestogether with a non-JSONresponserequestSchemaor a multipartbodyon aGETorHEADendpoint
Headers and timeout
headers and timeout set defaults for one endpoint. A call can override both: per-call headers are merged over the endpoint's, whatever the case of their names, and a per-call timeout wins.
Headers that every endpoint needs, such as authorization, belong on the HTTP client rather than on each declaration.
Client options
clientOptions passes keys through to your HTTP client that Builder itself has no opinion about, such as withCredentials (axios and @navios/http) or credentials (fetch and @navios/http).
It cannot override what Builder controls: method, url, params, data, signal, timeout and responseType are always set from the declaration and the call. headers in clientOptions are sent, merged underneath the endpoint's headers and the headers of the call.
Reading a declaration back
The options object is available unchanged as endpoint.config. Use it to build tooling on top of your declarations, or to reuse a schema.
Type helpers
When you need the types of an endpoint elsewhere — a function parameter, a component prop — derive them from the declaration.