http-promises

1.2.2 • Public • Published

http-promises

Build Status

Consistent HTTP request API on both server and browser using promises.

API

  • http.get(url)
  • http.post(url, { payload })
  • http.put(url, { payload })
  • http.delete(url)
  • http.header(key, value)

Usage

Server

import http from "http-promises/server";
 
let URL = "http://domain.com/foo";
http.get(URL)
  .then(result => { ... })
  .catch(err => { throw err; });
 
http.put(URL, { foo: 123 })
  .then(result => { ... })
  .catch(err => { throw err; });
 

Headers

Add headers by calling the chainable header(key, value) method:

 
http
  .header("Context-Type", "application/json")
  .header("My-Header", 1234)
  .get("/endpoint")
  .then( ... )
 

Adding headers is immutable. Each call to header returns a fresh API. The root http API is not effected.

Browser (Client)

Using it within the browser is exactly the same as the server, just require "http-promises/browser"

import http from "http-promises/browser";
 
http.get("/foo")
  .then(result => { ... })
  .catch(err => { throw err; });
 

Test

npm test

License: MIT

Readme

Keywords

Package Sidebar

Install

npm i http-promises

Weekly Downloads

3

Version

1.2.2

License

MIT

Last publish

Collaborators

  • philcockfield