httpuv

2.0.2 • Public • Published

httpuv

httpuv is a node.js library for making http requests with a clear API and zero dependencies.

  • Simple API
  • Lightweight ( < 3 KB )
  • Zero dependencies

API

GET
httpuv.get(url[, { [headers]: { ... }, [query]: { ... } }]);
POST
httpuv.post(url[, { [headers]: { ... }, [query]: { ... }, [body]: ... }]);
PUT
httpuv.put(url[, { [headers]: { ... }, [query]: { ... }, [body]: ... }]);
PATCH
httpuv.patch(url[, { [headers]: { ... }, [query]: { ... }, [body]: ... }]);
DELETE
httpuv.delete(url[, { [headers]: { ... }, [query]: { ... } }]);

Usage

const httpuv = require('httpuv');
 
...
// inside async function
// Getting data with query params
const response = await httpuv.get('https://foo.com/bar', {
  query: { baz: 1 }
}); // results in GET https://foo.com/bar?baz=1
 
 
...
// inside async function
// Posting a data with headers
try {
    const response = await httpuv.post('https://foo.com/bar', {
      body: { baz: 1 },
      headers: { 'Authentication': 'Bearer ...' },
    })
  console.log(`status code ${response.statusCode}`);
  console.log(`status message ${response.statusMessage}`);
  console.log(`response body ${JSON.stringify(response.data)}`);
} catch (e) {
  console.log(`status code ${response.statusCode}`);
  console.log(`status message ${response.statusMessage}`);
  console.log(`Error ${JSON.stringify(response.error)}`); 
}

Package Sidebar

Install

npm i httpuv

Weekly Downloads

1

Version

2.0.2

License

MIT

Unpacked Size

5.93 kB

Total Files

4

Last publish

Collaborators

  • vik