simple-json-request

1.0.0 • Public • Published

simple-json-request

Build Status Coverage Status NPM version JavaScript Style Guide Greenkeeper badge

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. options may be a string representing a url. 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.

put(options)

A convenience function that uses the method PUT by default.

delete(options)

A convenience function that uses the method DELETE by default.

head(options)

A convenience function that uses the method HEAD by default.

patch(options)

A convenience function that uses the method PATCH 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

Package Sidebar

Install

npm i simple-json-request

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.15 kB

Total Files

7

Last publish

Collaborators

  • serayaeryn