UNPKG

1.95 kBMarkdownView Raw
1# http-promises
2Consistent 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
15On the server:
16
17```js
18import http from "http-promises/server";
19
20let URL = "http://domain.com/foo";
21http.get(URL)
22 .then((result) => { ... })
23 .catch((err) => { throw err; });
24
25http.put(URL, { foo: 123 })
26 .then((result) => { ... })
27 .catch((err) => { throw err; });
28
29```
30
31Using it within the browser is exactly the same as the server, just require `"http-promises/browser"`
32
33```js
34import http from "http-promises/browser";
35
36http.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)
50Copyright © 2015, **Phil Cockfield**
51
52Permission is hereby granted, free of charge, to any person obtaining a copy
53of this software and associated documentation files (the "Software"), to deal
54in the Software without restriction, including without limitation the rights
55to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
56copies of the Software, and to permit persons to whom the Software is
57furnished to do so, subject to the following conditions:
58
59The above copyright notice and this permission notice shall be included in
60all copies or substantial portions of the Software.
61
62THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
68THE SOFTWARE.