New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

z-api

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

z-api

Create an API/Server without having to create the actual server yourself, all you have to worry about is the routes. ## Install ```sh npm i --save z-api ``` ## Usage ```js const Zapi = require('z-api'), api = new Zapi() ```

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
2
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

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 = require('z-api'),
  api = new Zapi()

Add route

const route = {
  method: 'GET', //Default is GET if not specified, Must be in caps
  path: '/', //Default is '/' if not specified,
  handler: (req, res) => {
    /*
    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.end('The api works)
  }
}

api.addRoute(route)

Remove route

api.removeRoute('GET', '/') //Method and path

Options

Options can be passed set when initialising the class, or they can be set later on.

On initialisation

api = new Zapi({
  port: 80
})

After initialisation

api.config.port = 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: '/',
  handler: (req, res) => {
    res.send('Default route')
  }
}

Middleware

Middleware is run in parallel for the best performance. To add middleware use the addMiddleware function.

api.addMiddleware((req, res, next) => {
  console.dir(req)
  next()
})

Keywords

api

FAQs

Package last updated on 27 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts