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

node-callapi

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-callapi

Making api call with node-fetch, with middleware.

latest
Source
npmnpm
Version
1.2.2
Version published
Maintainers
1
Created
Source

Node Call API

Making api call with node-fetch, with middleware.

npm version CircleCI Coverage Status

Basic usage

const Caller = require('node-callapi');
const caller = new Caller(setting);

caller.call(endpoint, options)

Constructor

new Caller(options);

options.middlewares

middlewares will be applied after every request finished.

Middleware

a middleware is an async function, it recevied an object. and returns a object that has the shape same as received data.

async function middleware(data) {
  const {
    // fetch options
    fetchOptions,

    // the endpoint
    url,

    // response, if no response, it will be null
    response,

    // the request duration
    duration,

    // if any error occured, it will be an Error instance
    error,

    // the result data, it will be one of [array, object, string, null]
    data,
  } = data;
  // do something
  return result;
}

data.error

namedescription
error.statusthe response status
error.fetchOptionsthe fetch options
error.durationthe time of the fetch request processing time
error.datathe data from server, it will parsed even if request failed
error.responsethe full response object
error.urlthe fetch url

api

call(url, options)

url should use absolute url.

it will return the parsed result.

options.method(optional)

request method. should be one of ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'TRACE', 'HEAD', 'CONNECT'].

options.data

send data to server if use 'POST', 'PUT' method.

options.middlewares

append middlewares. should be a valid middleware.

options.headers

append headers. should be an key-value object.

FAQs

Package last updated on 03 Jul 2018

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