npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@whook/http-router

v16.0.0

Published

The Whook base HTTP router

Downloads

754

Readme

@whook/http-router

The Whook base HTTP router

GitHub license

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

Functions

initHTTPRouter(services) ⇒ Promise

Initialize an HTTP router

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

| Param | Type | Default | Description | | --- | --- | --- | --- | | services | Object | | The services the server depends on | | services.ENV | Object | | The injected 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 |

initHTTPRouter~httpRouter(req, res) ⇒ Promise

Handle an HTTP incoming message

Kind: inner method of initHTTPRouter
Returns: Promise - A promise resolving when the operation completes

| Param | Type | Description | | --- | --- | --- | | req | HTTPRequest | A raw NodeJS HTTP incoming message | | res | HTTPResponse | A raw NodeJS HTTP response |

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

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

    // Do something with that operation
  });

dereferenceOpenAPIOperations(API, operations) ⇒ Object

Dereference API operations and transform OpenAPISchemas into JSONSchemas

Kind: global function
Returns: Object - The dereferenced OpenAPI operations

| Param | Type | Description | | --- | --- | --- | | API | Object | An OpenAPI object | | operations | Object | The OpenAPI operation objects |

initErrorHandler(services) ⇒ Promise

Initialize an error handler for the HTTP router

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

| Param | Type | Description | | --- | --- | --- | | services | Object | The services the server depends on | | services.ENV | Object | The app ENV | | [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 |

initErrorHandler~errorHandler(transactionId, responseSpec, err) ⇒ Promise

Handle an HTTP transaction error and map it to a serializable response

Kind: inner method of initErrorHandler
Returns: Promise - A promise resolving when the operation completes

| Param | Type | Description | | --- | --- | --- | | transactionId | String | A raw NodeJS HTTP incoming message | | responseSpec | Object | The response specification | | err | YHTTPError | The encountered error |

Authors

License

MIT