whook
v3.1.3
Published
Build strong and efficient REST web services.
Downloads
33
Readme
whook
Build strong and efficient REST web services.
whook
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 definition while ingredients are handlers, services and their configuration.
Principles
Whook work by adding ingredients to you API:
- configuration: Whokk look ups for
config/{NODE_ENV}/config.js
files. It creates constants you can inject in your handlers and services. - API: It defines the various endpoint of you API and how to map these to handlers thanks to the well known OpenAPI format (formerly Swagger),
- handlers: the code that implement those endpoints,
- services: various services that deal with global states,
- wrappers: higher order functions you can apply to handlers (CORS, authentication...).
Whook is built over Knifecyle which is great for adding or easily override/wrap a lot of its core component. It brings instrumentation and testability to your code bases.
Whook also rely on swagger-http-router
which is a the heart of its routing
system.
Work in progress
I'd like to end up with a quick start guide looking like that:
# Initialize the project
mkdir simple_server && cd simple_server;
npm init whook simple_server;
npm install;
# Check install with a dry run of the server
DRY_RUN=1 npm run start
But atm, I only need it for my projects so leaving this as is in the meanwhile. If you're still motivated to use it, you should take a look to this project's architecture notes.
API
Functions
runServer(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 |
prepareServer($) ⇒
Kind: global function
Returns: Promise
A promise of the Knifecycle instance
| Param | Type | Description | | --- | --- | --- | | $ | Knifecycle | The Knifecycle instance to set the various services |
initENV(services, [log]) ⇒ Promise.<Object>
Initialize the ENV service using process env plus dotenv files
Kind: global function
Returns: Promise.<Object> - A promise of an object containing the actual env vars.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | Object | | The services ENV depends on |
| services.NODE_ENV | Object | | The injected NODE_ENV value to lookk for .env.${NODE_ENV}
env file |
| services.PWD | Object | | The process current working directory |
| [services.BASE_ENV] | Object | {} | An optional base environment |
| [log] | Object | noop | An optional logging service |
initHOST(services, [log]) ⇒ 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 | | [log] | Object | noop | An optional logging service |
initPORT(services, [log]) ⇒ 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 | | [log] | Object | noop | An optional logging service |