@whook/http-router

The Whook base HTTP router

Usage no npm install needed!

<script type="module">
  import whookHttpRouter from 'https://cdn.skypack.dev/@whook/http-router';
</script>

README

@whook/http-router

The Whook base HTTP router

GitHub license NPM version

The Whook's httpRouter service is responsible for wiring routes definitions to their actual implementation while filtering inputs and ensuring good outputs.

This is the default implementation of the Framework but it can be replaced or customized by setting your own configurations to replace the default ones (see the API section).

API

Members

defaultPromise

Initialize an error handler for the HTTP router

defaultPromise

Initialize an HTTP router

Functions

flattenOpenAPI(API)Object

Flatten the inputed OpenAPI file object

getOpenAPIOperations(API)Array

Return a OpenAPI operation in a more convenient way to iterate onto its operations

default ⇒ Promise

Initialize an error handler for the HTTP router

Kind: global variable
Returns: Promise - A promise of a function to handle errors

Param Type Description
services Object The services the server depends on
services.NODE_ENV Object The injected NODE_ENV value
[services.DEBUG_NODE_ENVS] Array The environnement that activate debugging (prints stack trace in HTTP errors responses)
[services.STRINGIFYERS] Object The synchronous body stringifyers
[services.ERRORS_DESCRIPTORS] Object An hash of the various error descriptors
[services.DEFAULT_ERROR_CODE] Object A string giving the default error code

default ⇒ Promise

Initialize an HTTP router

Kind: global variable
Returns: Promise - A promise of a function to handle HTTP requests.

Param Type Default Description
services Object The services the server depends on
services.NODE_ENV Object The injected NODE_ENV value
[services.DEBUG_NODE_ENVS] Array The environnement that activate debugging (prints stack trace in HTTP errors responses)
[services.BUFFER_LIMIT] String The maximum bufferisation before parsing the request body
[services.BASE_PATH] String API base path
services.HANDLERS Object The handlers for the operations decribe by the OpenAPI API definition
services.API Object The OpenAPI definition of the API
[services.PARSERS] Object The synchronous body parsers (for operations that defines a request body schema)
[services.STRINGIFYERS] Object The synchronous body stringifyers (for operations that defines a response body schema)
[services.ENCODERS] Object A map of encoder stream constructors
[services.DECODERS] Object A map of decoder stream constructors
[services.QUERY_PARSER] Object A query parser with the strict-qs signature
[services.log] function noop A logging function
services.httpTransaction function A function to create a new HTTP transaction

flattenOpenAPI(API) ⇒ Object

Flatten the inputed OpenAPI file object

Kind: global function
Returns: Object - The flattened OpenAPI definition

Param Type Description
API Object An Object containing a parser OpenAPI JSON

getOpenAPIOperations(API) ⇒ Array

Return a OpenAPI operation in a more convenient way to iterate onto its operations

Kind: global function
Returns: Array - An array of all the OpenAPI operations

Param Type Description
API Object The flattened OpenAPI defition

Example

(
  await getOpenAPIOperations(API)
).map((operation) => {
   const { path, method, operationId, parameters } = operation;

  // Do something with that operation
});

Authors

License

MIT