Build strong and efficient REST web services.
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.
Functions
- prepareServer(injectedNames, $) ⇒
Runs the Whook server
- prepareEnvironment($) ⇒
Prepare the Whook server environment
- initAPIDefinitions(services) ⇒
Promise.<String>
Initialize the APIDEFINITIONS service according to the porject handlers.
- initBaseURL(services) ⇒
Promise.<String>
Initialize the BASEURL 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 serverKind: 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 environmentKind: 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 APIDEFINITIONS 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 APIDEFINITIONS depends on |
| services.WHOOKPLUGINS | Array.<String>
| | The activated plugins |
| services.WHOOKRESOLVEDPLUGINS | Array
| | The resolved plugins |
| services.IGNOREDFILESSUFFIXES | Object
| | The files suffixes the autoloader must ignore |
| services.IGNOREDFILESPREFIXES | Object
| | The files prefixes the autoloader must ignore |
| services.FILTERAPIDEFINITION | 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 BASEURL 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 BASEURL 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 ENVKind: 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 ENVKind: 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 buildKind: 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.PROXYEDENVVARS | 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 namesKind: global function
Returns:
Promise.<string>
- A promise of a number representing the actual port.| Param | Type | Default | Description | | --- | --- | --- | --- | | services |
Object
| | The services WHOOKRESOLVEDPLUGINS depends on |
| services.WHOOKPLUGINS | 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.HANDLERSWRAPPERS | 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 |