1 | <p align="center" style="text-align: center"><img src="https://raw.githubusercontent.com/ethanent/phin/master/media/phin-textIncluded.png" width="250" alt="phin logo"/></p>
|
2 |
|
3 | ---
|
4 |
|
5 | > The ultra-lightweight Node.js HTTP client
|
6 |
|
7 | [Full documentation](https://ethanent.github.io/phin/) | [GitHub](https://github.com/ethanent/phin) | [NPM](https://www.npmjs.com/package/phin)
|
8 |
|
9 |
|
10 | ## Simple Usage
|
11 |
|
12 | ```javascript
|
13 | const p = require('phin')
|
14 |
|
15 | p('https://ethanent.me', (err, res) => {
|
16 | if (!err) console.log(res.body)
|
17 | })
|
18 | ```
|
19 |
|
20 |
|
21 | ## Install
|
22 |
|
23 | ```
|
24 | npm install phin
|
25 | ```
|
26 |
|
27 |
|
28 | ## Why phin?
|
29 |
|
30 | phin is **trusted** by some really important projects. The hundreds of contributors at [Less](https://github.com/less/less.js), for example, depend on phin as part of their development process.
|
31 |
|
32 | Also, phin is super **lightweight**. Like **99.8% smaller than request** lightweight. To compare to other libraries, see [phin vs. the Competition](https://github.com/ethanent/phin/blob/master/README.md#phin-vs-the-competition).
|
33 |
|
34 | <img src="https://pbs.twimg.com/media/DSPF9TaUQAA0tIe.jpg:large" alt="phin became 33% lighter with release 2.7.0!"/>
|
35 |
|
36 |
|
37 | ## Quick Demos
|
38 |
|
39 | Simple POST:
|
40 |
|
41 | ```javascript
|
42 | p({
|
43 | url: 'https://ethanent.me',
|
44 | method: 'POST',
|
45 | data: {
|
46 | hey: 'hi'
|
47 | }
|
48 | })
|
49 | ```
|
50 |
|
51 | Promisified:
|
52 |
|
53 | ```javascript
|
54 | const p = require('phin').promisified
|
55 | ```
|
56 |
|
57 | ```javascript
|
58 | ;(async () => {
|
59 | const res = await p({
|
60 | url: 'https://ethanent.me'
|
61 | })
|
62 |
|
63 | console.log(res.body)
|
64 | })()
|
65 | ```
|
66 |
|
67 | Simple parsing of JSON:
|
68 |
|
69 | ```javascript
|
70 | // (In async function in this case.)
|
71 |
|
72 | const res = await p({
|
73 | url: 'https://ethanent.me/name',
|
74 | parse: 'json'
|
75 | })
|
76 |
|
77 | console.log(res.body.first)
|
78 | ```
|
79 |
|
80 |
|
81 | ## Documentation
|
82 |
|
83 | See [the phin documentation](https://ethanent.github.io/phin/).
|
84 |
|
85 | `phin` has [`util.promisify`](https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original) support. The promisified library can also be accessed with `require('phin').promisified`!
|
86 |
|
87 |
|
88 | ## phin vs. the Competition
|
89 |
|
90 | <img src="https://pbs.twimg.com/media/DSLU_UcUEAI4bgc.jpg:large" alt="Request is over 6MB in size. phin is just 25KB in size."/>
|
91 |
|
92 | phin is super lightweight, and *it's getting lighter all the time*.
|
93 |
|
94 | It contains all of the common HTTP client features included in competing libraries!
|
95 |
|
96 | Package | Size (KB) | Dependencies<br />(Tree Count) | Size Comparison<br />(vs. phin)
|
97 | --- | --- | --- | ---
|
98 | request | 4,446 | [53](http://npm.anvaka.com/#/view/2d/request) | 444.6x
|
99 | superagent | 1,235 | [24](http://npm.anvaka.com/#/view/2d/superagent) | 123.5x
|
100 | got | 664 | [44](http://npm.anvaka.com/#/view/2d/got) | 66.4x
|
101 | snekfetch | 107 | [0](http://npm.anvaka.com/#/view/2d/snekfetch) | 10.7x
|
102 | phin | 10 | [0](http://npm.anvaka.com/#/view/2d/phin) | 1x |
\ | No newline at end of file |