npm.io
3.0.0 • Published 3 years ago

callarest

Licence
MIT
Version
3.0.0
Deps
2
Size
12 kB
Vulns
0
Weekly
0
Stars
1

Callarest

A simple tool to natively make http(s) requests in node

Example Usage

Verbose

import { callarest } from 'callarest';

callarest({
  method: 'post',
  body: JSON.stringify({ hello: 'world' }),
  headers: {
    'Content-Type': 'application/json'
  },
  url: 'https://www.example.com'
}, function (error, rest) {
  if (error) {
    console.log('There was an error:', error);
  }
  console.log('The request was:', rest.request);
  console.log('The response was:', rest.response);
  console.log('The body was:', rest.body);

  // body will be a string
})
JSON
import { callarestJson } from 'callarest';

callarestJson({
  method: 'post',
  body: { hello: 'world' },
  url: 'https://www.example.com'
}, function (error, rest) {
  if (error) {
    console.log('There was an error:', error);
  }
  console.log('The request was:', rest.request);
  console.log('The response was:', rest.response);
  console.log('The body was:', rest.body);

  // body will be a javascript Object
})

License

This project is licensed under the terms of the MIT license.

Keywords