npm

Join us for the upcoming webinar, "Enterprise JavaScript done right: the tools you love, the security you need."Sign up here »

simple-json-request

0.5.2 • Public • Published

simple-json-request

Greenkeeper badge Build Status Coverage Status NPM version JavaScript Style Guide

A simple module to make json requests with Promise support, that wraps around the simple-get module.

Installation

npm install simple-json-request

Usage

const request = require('simple-json-request')
 
request.request({
  method: 'GET',
  url: 'http://example.com'
})
  .then((data) => {
    // ...
  })
  .catch((error) => {
    // ...
  });

API

request(options)

Executes a request with the specified options. Returns a promise that either resolves the parsed data or rejects with an error.

get(options)

A convenience function that uses the method GET by default.

post(options)

A convenience function that uses the method POST by default.

options

url

The url to request.

method

The http method. Supports GET, POST, PUT, PATCH, HEAD and DELETE.

timeout

Allows to set a socket timeout in milliseconds.

headers

Allows to pass headers with the request.

body

The body of a post request.

form

The form data of a post request with Content-Type : application/x-www-form-urlencoded.

readTimeout

Allows to set a read timeout in milliseconds.

maxRedirects

The maximum number of redirects to follow in a request. Defaults to 10.

parser

Allows to specify a custom json parser like turbo-json-parse.

License

MIT

install

npm i simple-json-request

Downloadsweekly downloads

24

version

0.5.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability