开发者社区> 镜像站> NPM> http-promises
http-promises
Consistent HTTP request API on both server and browser using promises.
Last updated 5 years ago by philcockfield .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install http-promises 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.2.2                                ...           latest (5 years ago)

21 Versions

  • 1.2.2                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.10                                ...           5 years ago
  • 1.0.9                                ...           5 years ago
  • 1.0.8                                ...           5 years ago
  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.6                                ...           5 years ago
  • 0.0.5                                ...           5 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (6)