16.1.0 • Published 2 months ago

@whook/whook v16.1.0

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

@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

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

ParamTypeDescription
injectedNamesArray.<String>Root dependencies names to instanciate and return
$KnifecycleThe 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

ParamTypeDescription
$KnifecycleThe 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.

ParamTypeDefaultDescription
servicesObjectThe services API_DEFINITIONS depends on
services.WHOOK_PLUGINSArray.<String>The activated plugins
services.WHOOK_RESOLVED_PLUGINSArrayThe resolved plugins
services.IGNORED_FILES_SUFFIXESObjectThe files suffixes the autoloader must ignore
services.IGNORED_FILES_PREFIXESObjectThe files prefixes the autoloader must ignore
services.FILTER_API_DEFINITIONObjectAllows to filter endpoints if the custom function returns true
services.importerObjectA service allowing to dynamically import ES modules
services.logObjectnoopAn 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.

ParamTypeDefaultDescription
servicesObjectThe services BASE_URL depends on
services.ENVObjectThe process environment
services.CONFIGObjectThe injected CONFIG value
services.PROTOCOLObjectThe injected PROTOCOL value
services.HOSTObjectThe injected HOST value
services.PORTObjectThe injected PORT value
services.logObjectnoopAn 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.

ParamTypeDescription
constantsObjectThe 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.

ParamTypeDefaultDescription
servicesObjectThe services HANDLERS depends on
services.WRAPPERSArrayAn optional list of wrappers to inject
services.logObjectnoopAn optional logging service
services.HANDLERSObjectThe 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.

ParamTypeDefaultDescription
servicesObjectThe services HOST depends on
services.ENVObject{}An optional environment object
services.logObjectnoopAn optional logging service
services.importerObjectA 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.

ParamTypeDefaultDescription
servicesObjectThe services PORT depends on
services.ENVObject{}An optional environment object
services.logObjectnoopAn optional logging service
services.importerObjectA 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.

ParamTypeDefaultDescription
servicesObjectThe services ENV depends on
services.PROXYED_ENV_VARSObject{}A list of environment variable names to proxy
services.logObjectnoopAn 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.

ParamTypeDefaultDescription
servicesObjectThe services WHOOK_RESOLVED_PLUGINS depends on
services.WHOOK_PLUGINSArray.<String>The activated plugins
services.logObjectnoopAn 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.

ParamTypeDefaultDescription
servicesObjectThe services WRAPPERS depends on
services.HANDLERS_WRAPPERSArrayThe global wrappers names to wrap the handlers with
services.logObjectnoopAn optional logging service
services.WRAPPERSObjectThe dependencies must all be injected wrappers

Authors

License

MIT

16.1.0

2 months ago

16.0.1

2 months ago

16.0.0

2 months ago

15.0.0

3 months ago

13.0.0

9 months ago

13.1.0

9 months ago

13.2.0

7 months ago

14.0.0

6 months ago

13.2.1

7 months ago

10.0.5

2 years 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

12.0.2

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

3 years ago

8.5.0

3 years ago

8.4.2

3 years ago

8.4.1

3 years ago

8.4.0

3 years ago

8.3.0

3 years ago

8.1.0

3 years ago

8.1.1

3 years ago

8.0.4

3 years ago

8.0.3

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

8.0.2

3 years ago

7.1.5

3 years ago

7.1.4

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

4 years ago

5.1.6

4 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.2

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