1.2.2 • Published 9 years ago
http-promises v1.2.2
http-promises
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
1.2.2
9 years ago
1.2.1
9 years ago
1.2.0
9 years ago
1.1.0
9 years ago
1.0.10
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.7
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago
0.0.6
9 years ago
0.0.5
9 years ago
0.0.4
9 years ago
0.0.3
9 years ago
0.0.2
9 years ago
0.0.1
9 years ago