1 | # http-promises
|
2 | Consistent HTTP request API on both server and browser using promises.
|
3 |
|
4 | [![Build Status](https://travis-ci.org/philcockfield/http-promises.svg)](https://travis-ci.org/philcockfield/http-promises)
|
5 |
|
6 | ## API
|
7 |
|
8 | - `http.get(url)`
|
9 | - `http.post(url, { payload })`
|
10 | - `http.put(url, { payload })`
|
11 | - `http.delete(url)`
|
12 |
|
13 |
|
14 | ## Usage
|
15 | On the server:
|
16 |
|
17 | ```js
|
18 | import http from "http-promises/server";
|
19 |
|
20 | let URL = "http://domain.com/foo";
|
21 | http.get(URL)
|
22 | .then((result) => { ... })
|
23 | .catch((err) => { throw err; });
|
24 |
|
25 | http.put(URL, { foo: 123 })
|
26 | .then((result) => { ... })
|
27 | .catch((err) => { throw err; });
|
28 |
|
29 | ```
|
30 |
|
31 | Using it within the browser is exactly the same as the server, just require `"http-promises/browser"`
|
32 |
|
33 | ```js
|
34 | import http from "http-promises/browser";
|
35 |
|
36 | http.get("/foo")
|
37 | .then((result) => { ... })
|
38 | .catch((err) => { throw err; });
|
39 |
|
40 | ```
|
41 |
|
42 |
|
43 | ## Test
|
44 | npm test
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | ## License (MIT)
|
50 | Copyright © 2015, **Phil Cockfield**
|
51 |
|
52 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
53 | of this software and associated documentation files (the "Software"), to deal
|
54 | in the Software without restriction, including without limitation the rights
|
55 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
56 | copies of the Software, and to permit persons to whom the Software is
|
57 | furnished to do so, subject to the following conditions:
|
58 |
|
59 | The above copyright notice and this permission notice shall be included in
|
60 | all copies or substantial portions of the Software.
|
61 |
|
62 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
63 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
64 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
65 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
66 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
67 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
68 | THE SOFTWARE.
|