Zapi
Create an API/Server without having to create the actual server yourself, all you have to worry about is the routes.
Install
npm i --save z-api
Usage
const Zapi = api =
Add route
const route = method: 'GET' //Default is GET if not specified, Must be in caps path: '/' //Default is '/' if not specified, { /* req and res are the standard http objects A good guide on how to use them here https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/ */ res
Remove route
api //Method and path
Options
Options can be passed set when initialising the class, or they can be set later on.
On initialisation
api = port: 80
After initialisation
apiconfigport = 80
Used options
The following are config options that are currently used, more may be added in the future.
port
The port to run the server on, the default is 3002.
port: 3002
defaultRoute
The default route options to use if that option is not specified. The default method is GET. The default path is '/'. The default handler sends a response saying 'Default route'.
defaultRoute: method: 'GET' path: '/' { res }
Middleware
Middleware is run in parallel for the best performance. To add middleware use the addMiddleware function.
api