@whook/whook
TypeScript icon, indicating that this package has built-in type declarations

16.1.0 • Public • Published

@whook/whook

Build strong and efficient REST web services.

GitHub license

whook allows you to create REST web services by providing its ingredients and the recipe to make it work altogether.

The recipe is your Open API (OAS3) definition while ingredients are handlers, wrappers, services, commands and their configuration.

Quick start

npm init @whook

Looks at the repository's main README for more documentation.

API

Functions

prepareServer(injectedNames, $)

Runs the Whook server

prepareEnvironment($)

Prepare the Whook server environment

initAPIDefinitions(services)Promise.<String>

Initialize the API_DEFINITIONS service according to the porject handlers.

initBaseURL(services)Promise.<String>

Initialize the BASE_URL service according to the HOST/PORT so that applications fallbacks to that default base URL.

initBuildConstants(constants)Promise.<Object>

Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

initHandlers(services)Promise.<function()>

Initialize the Whook handlers used byt the router to know which handler to run for a given open API operation id.

initHost(services)Promise.<String>

Initialize the HOST service from ENV or auto-detection if none specified in ENV

initPort(services)Promise.<Number>

Initialize the PORT service from ENV or auto-detection if none specified in ENV

wrapEnvForBuild(services)Promise.<Object>

Wrap the ENV service in order to filter ENV vars for the build

initResolvedWhookPlugins(services)Promise.<string>

Resolves the Whook plugins from their names

initWrappers(services)Promise.<function()>

A simple passthrough service proxing the WRAPPERS.

prepareServer(injectedNames, $) ⇒

Runs the Whook server

Kind: global function
Returns: Object A promise of the injected services

Param Type Description
injectedNames Array.<String> Root dependencies names to instanciate and return
$ Knifecycle The Knifecycle instance to use for the server run

prepareEnvironment($) ⇒

Prepare the Whook server environment

Kind: global function
Returns: Promise A promise of the Knifecycle instance

Param Type Description
$ Knifecycle The Knifecycle instance to set the various services

initAPIDefinitions(services) ⇒ Promise.<String>

Initialize the API_DEFINITIONS service according to the porject handlers.

Kind: global function
Returns: Promise.<String> - A promise of a containing the actual host.

Param Type Default Description
services Object The services API_DEFINITIONS depends on
[services.WHOOK_PLUGINS] Array.<String> The activated plugins
services.WHOOK_RESOLVED_PLUGINS Array The resolved plugins
[services.IGNORED_FILES_SUFFIXES] Object The files suffixes the autoloader must ignore
[services.IGNORED_FILES_PREFIXES] Object The files prefixes the autoloader must ignore
[services.FILTER_API_DEFINITION] Object Allows to filter endpoints if the custom function returns true
services.importer Object A service allowing to dynamically import ES modules
[services.log] Object noop An optional logging service

initBaseURL(services) ⇒ Promise.<String>

Initialize the BASE_URL service according to the HOST/PORT so that applications fallbacks to that default base URL.

Kind: global function
Returns: Promise.<String> - A promise of a containing the actual host.

Param Type Default Description
services Object The services BASE_URL depends on
services.ENV Object The process environment
services.CONFIG Object The injected CONFIG value
[services.PROTOCOL] Object The injected PROTOCOL value
services.HOST Object The injected HOST value
services.PORT Object The injected PORT value
[services.log] Object noop An optional logging service

initBuildConstants(constants) ⇒ Promise.<Object>

Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

Kind: global function
Returns: Promise.<Object> - A promise of an object containing the gathered constants.

Param Type Description
constants Object The serializable constants to gather

Example

import { initBuildConstants } from '@whook/whook';
import { alsoInject } from 'knifecycle';

export default alsoInject(['MY_OWN_CONSTANT'], initBuildConstants);

initHandlers(services) ⇒ Promise.<function()>

Initialize the Whook handlers used byt the router to know which handler to run for a given open API operation id.

Kind: global function
Returns: Promise.<function()> - A promise of the HANDLERS hash.

Param Type Default Description
services Object The services HANDLERS depends on
services.WRAPPERS Array An optional list of wrappers to inject
[services.log] Object noop An optional logging service
services.HANDLERS Object The rest is a hash of handlers mapped by their operation id

initHost(services) ⇒ Promise.<String>

Initialize the HOST service from ENV or auto-detection if none specified in ENV

Kind: global function
Returns: Promise.<String> - A promise of a containing the actual host.

Param Type Default Description
services Object The services HOST depends on
[services.ENV] Object {} An optional environment object
[services.log] Object noop An optional logging service
services.importer Object A service allowing to dynamically import ES modules

initPort(services) ⇒ Promise.<Number>

Initialize the PORT service from ENV or auto-detection if none specified in ENV

Kind: global function
Returns: Promise.<Number> - A promise of a number representing the actual port.

Param Type Default Description
services Object The services PORT depends on
[services.ENV] Object {} An optional environment object
[services.log] Object noop An optional logging service
services.importer Object A service allowing to dynamically import ES modules

wrapEnvForBuild(services) ⇒ Promise.<Object>

Wrap the ENV service in order to filter ENV vars for the build

Kind: global function
Returns: Promise.<Object> - A promise of an object containing the reshaped env vars.

Param Type Default Description
services Object The services ENV depends on
[services.PROXYED_ENV_VARS] Object {} A list of environment variable names to proxy
[services.log] Object noop An optional logging service

initResolvedWhookPlugins(services) ⇒ Promise.<string>

Resolves the Whook plugins from their names

Kind: global function
Returns: Promise.<string> - A promise of a number representing the actual port.

Param Type Default Description
services Object The services WHOOK_RESOLVED_PLUGINS depends on
[services.WHOOK_PLUGINS] Array.<String> The activated plugins
[services.log] Object noop An optional logging service

initWrappers(services) ⇒ Promise.<function()>

A simple passthrough service proxing the WRAPPERS.

Kind: global function
Returns: Promise.<function()> - A promise of the HANDLERS hash.

Param Type Default Description
services Object The services WRAPPERS depends on
[services.HANDLERS_WRAPPERS] Array The global wrappers names to wrap the handlers with
[services.log] Object noop An optional logging service
services.WRAPPERS Object The dependencies must all be injected wrappers

Authors

License

MIT

Package Sidebar

Install

npm i @whook/whook

Weekly Downloads

93

Version

16.1.0

License

MIT

Unpacked Size

930 kB

Total Files

290

Last publish

Collaborators

  • nfroidure