16.0.0 • Published 2 months ago

@whook/http-router v16.0.0

Weekly downloads
43
License
MIT
Repository
github
Last release
2 months ago

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

ParamTypeDefaultDescription
servicesObjectThe services the server depends on
services.ENVObjectThe injected ENV value
services.DEBUG_NODE_ENVSArrayThe environnement that activate debugging (prints stack trace in HTTP errors responses)
services.BUFFER_LIMITStringThe maximum bufferisation before parsing the request body
services.BASE_PATHStringAPI base path
services.HANDLERSObjectThe handlers for the operations decribe by the OpenAPI API definition
services.APIObjectThe OpenAPI definition of the API
services.PARSERSObjectThe synchronous body parsers (for operations that defines a request body schema)
services.STRINGIFYERSObjectThe synchronous body stringifyers (for operations that defines a response body schema)
services.ENCODERSObjectA map of encoder stream constructors
services.DECODERSObjectA map of decoder stream constructors
services.QUERY_PARSERObjectA query parser with the strict-qs signature
services.logfunctionnoopA logging function
services.httpTransactionfunctionA 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

ParamTypeDescription
reqHTTPRequestA raw NodeJS HTTP incoming message
resHTTPResponseA raw NodeJS HTTP response

flattenOpenAPI(API) ⇒ Object

Flatten the inputed OpenAPI file object

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

ParamTypeDescription
APIObjectAn 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

ParamTypeDescription
APIObjectThe 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

ParamTypeDescription
APIObjectAn OpenAPI object
operationsObjectThe 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

ParamTypeDescription
servicesObjectThe services the server depends on
services.ENVObjectThe app ENV
services.DEBUG_NODE_ENVSArrayThe environnement that activate debugging (prints stack trace in HTTP errors responses)
services.STRINGIFYERSObjectThe synchronous body stringifyers
services.ERRORS_DESCRIPTORSObjectAn hash of the various error descriptors
services.DEFAULT_ERROR_CODEObjectA 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

ParamTypeDescription
transactionIdStringA raw NodeJS HTTP incoming message
responseSpecObjectThe response specification
errYHTTPErrorThe encountered error

Authors

License

MIT

16.0.0

2 months ago

15.0.0

2 months ago

13.1.0

9 months ago

13.2.0

7 months ago

14.0.0

6 months ago

13.0.0

9 months ago

10.0.6

2 years ago

10.0.0

2 years ago

10.0.1

2 years ago

10.0.2

2 years ago

10.0.3

2 years ago

10.0.4

2 years ago

12.0.0

1 year ago

12.0.1

1 year ago

11.0.0

1 year ago

11.0.1

1 year ago

9.0.1

2 years ago

9.0.0

2 years ago

8.5.0

3 years ago

8.4.2

3 years ago

8.3.0

3 years ago

8.1.0

3 years ago

8.0.4

3 years ago

8.0.3

3 years ago

8.0.2

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

7.1.5

3 years ago

7.1.3

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.0

3 years ago

6.0.0

3 years ago

5.1.6

3 years ago

5.1.5

3 years ago

5.1.4

4 years ago

5.1.3

4 years ago

5.1.2

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.0

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.4

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

4.0.0-alpha.44

4 years ago

4.0.0-alpha.43

4 years ago

4.0.0-alpha.42

4 years ago

4.0.0-alpha.41

4 years ago

4.0.0-alpha.40

4 years ago

4.0.0-alpha.39

4 years ago

4.0.0-alpha.38

4 years ago

4.0.0-alpha.37

4 years ago

4.0.0-alpha.36

4 years ago

4.0.0-alpha.35

4 years ago

4.0.0-alpha.34

4 years ago

4.0.0-alpha.33

4 years ago

4.0.0-alpha.32

4 years ago

4.0.0-alpha.31

4 years ago

4.0.0-alpha.30

4 years ago

4.0.0-alpha.29

4 years ago

4.0.0-alpha.28

4 years ago

4.0.0-alpha.27

4 years ago

4.0.0-alpha.26

4 years ago

4.0.0-alpha.25

4 years ago

4.0.0-alpha.24

4 years ago

4.0.0-alpha.20

4 years ago

4.0.0-alpha.23

4 years ago

4.0.0-alpha.22

4 years ago

4.0.0-alpha.21

4 years ago

4.0.0-alpha.19

4 years ago

4.0.0-alpha.18

4 years ago

4.0.0-alpha.17

4 years ago

4.0.0-alpha.16

4 years ago

4.0.0-alpha.15

4 years ago

4.0.0-alpha.14

4 years ago

4.0.0-alpha.13

4 years ago

4.0.0-alpha.12

4 years ago

4.0.0-alpha.11

5 years ago

4.0.0-alpha.10

5 years ago

4.0.0-alpha.9

5 years ago

4.0.0-alpha.8

5 years ago

4.0.0-alpha.7

5 years ago

4.0.0-alpha.6

5 years ago

4.0.0-alpha.5

5 years ago

4.0.0-alpha.4

5 years ago

4.0.0-alpha.3

5 years ago

4.0.0-alpha.0

5 years ago