1.0.1 • Published 5 years ago

reach-client v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

HTTP client for node

Build Status

HTTP Client based on node's net package sockets.

Installation

npm i reach-client

Usage

const reach = require('reach-client');

reach(url, options)
  .then(response => console.log(response.getBody()))
  .catch(err => console.log(err.code);

The available options are:

OptionsTypeValues
methodstringHTTP method (GET, POST, PUT, PATCH, DELETE supported)
headersobjectAll HTTP request headers
bodyobject/stringHTTP request body

Examples

reach(
  'https://ptsv2.com/t/06t82-1549561768/post',
  {
    method: 'POST',
    headers: {},
    body: {
      fields: { name: 'firstname', surname: 'lastname' },
      file: './src/file.txt',
    },
  }).then((response) => {
    console.log(response.getBody())
  })
  .catch((err) => console.log(err.code));

reach(
  'https://ptsv2.com/t/06t82-1549561768/post',
  {
    method: 'PUT',
    headers: {},
    body: 'a=7&b=8'
  }).then((response) => {
    console.log(response.statusText)
  })
  .catch((err) => console.log(err.code));


reach(
  'https://jsonplaceholder.typicode.com/posts/1',
  {
    method: 'GET',
    headers: {},
  }).then((response) => {
    console.log(response.code)
  })
  .catch((err) => console.log(err.code));

Available response members

OptionsTypeValues
codenumberHTTP response code
statusTextstringHTTP response status
getBodyobjectHTTP response body
getHeadersobjectHTTP response body
1.0.1

5 years ago

1.0.0

5 years ago