Skip to content

Lightweight, promise-based library for making http requests

Notifications You must be signed in to change notification settings

sugojs/sugo-http-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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');

About

Lightweight, promise-based library for making http requests

Resources

Stars

Watchers

Forks

Packages

No packages published