@sugo/http-request
TypeScript icon, indicating that this package has built-in type declarations

2.4.4 • Public • Published

@sugo/http-request (http-request-promise-simple)

Dependency-less http methods for pure nodejs. Wraps the nodejs http module in promises and handles some of the request events (like building the request body).

How to install

npm install --save @sugo/http-request

Methods

All methods recieve an options parameter, this corresponds to the node http request options.

Additionally to the nodejs options, it also recieves a https boolean options in order to use a https request instead of a http request.

Some methods can be passed a data parameter, this corresponds to the request body. This must be an Object.

  • request(url, options): A generic http request, it uses by default the get method but can be used to make any type of request.

  • get(url, options): A wrapper for the request method that forces the request to be of the GET type.

  • head(url, options): A wrapper for the request method that forces the request to be of the HEAD type.

  • options(url, options): A wrapper for the request method that forces the request to be of the OPTIONS type.

  • connect(url, options): A wrapper for the request method that forces the request to be of the CONNECT type.

  • trace(url, options): A wrapper for the request method that forces the request to be of the TRACE type.

  • post(url, data, options): A wrapper for the request method that forces the request to be of the POST type.

  • put(url, data, options): A wrapper for the request method that forces the request to be of the PUT type.

  • patch(url, data, options): A wrapper for the request method that forces the request to be of the PATCH type.

  • deleteRequest(url, options): A wrapper for the request method that forces the request to be of the DELETE type.

Example - Promise

import httpClient = require('@sugo/http-request');
return httpClient
  .get('http://localhost:8080/foo/bar')
  .then(res => console.info(res.status))
  .catch(error => console.error(error));

Example - Async/Await

import httpClient = require('@sugo/http-request');
const res = await httpClient.get('http://localhost:8080/foo/bar');

Readme

Keywords

Package Sidebar

Install

npm i @sugo/http-request

Weekly Downloads

1

Version

2.4.4

License

ISC

Unpacked Size

19.1 kB

Total Files

10

Last publish

Collaborators

  • andrea.sucre
  • franciscojsucreg