2.0.5 • Published 2 years ago

@evokegroup/webrequest v2.0.5

Weekly downloads
55
License
ISC
Repository
bitbucket
Last release
2 years ago

@evokegroup/webrequest

Utility for making HTTP/HTTPS calls.

CommonJS

const { webRequest } = require('@evokgroup/webrequest');

ES Modules

import { webRequest } from '@evokegroup/webrequest';

Usage

webRequest({
  url: 'https://some.url.com',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: { send: 'this' },
  parseResponse: true // Pase true to parse the body as JSON data or return a string. Otherwise the response body will be a Buffer
})
  .then((webResponse) => {
    if (webResponse.statusCode === 200) {
      const data = webResponse.body; // parseResponse=true parsed the body and JSON data
      const name = data.name;
    } else {
      // do something
    }
  })
  .catch(reject);