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 | const res = await p('https://ethanent.me')
|
16 |
|
17 | console.log(res.body)
|
18 | ```
|
19 |
|
20 | Note that the above should be in an async context! phin also provides an unpromisified version of the library.
|
21 |
|
22 | ## Install
|
23 |
|
24 | ```
|
25 | npm install phin
|
26 | ```
|
27 |
|
28 |
|
29 | ## Why phin?
|
30 |
|
31 | 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.
|
32 |
|
33 | 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).
|
34 |
|
35 | <img src="https://pbs.twimg.com/media/DSPF9TaUQAA0tIe.jpg:large" alt="phin became 33% lighter with release 2.7.0!"/>
|
36 |
|
37 |
|
38 | ## Quick Demos
|
39 |
|
40 | Simple POST:
|
41 |
|
42 | ```javascript
|
43 | await p({
|
44 | url: 'https://ethanent.me',
|
45 | method: 'POST',
|
46 | data: {
|
47 | hey: 'hi'
|
48 | }
|
49 | })
|
50 | ```
|
51 |
|
52 | ## Unpromisified Usage
|
53 |
|
54 | ```javascript
|
55 | const p = require('phin').unpromisified
|
56 |
|
57 | p('https://ethanent.me', (err, res) => {
|
58 | if (!err) console.log(res.body)
|
59 | })
|
60 | ```
|
61 |
|
62 | Simple parsing of JSON:
|
63 |
|
64 | ```javascript
|
65 | // (In async function in this case.)
|
66 |
|
67 | const res = await p({
|
68 | url: 'https://ethanent.me/name',
|
69 | parse: 'json'
|
70 | })
|
71 |
|
72 | console.log(res.body.first)
|
73 | ```
|
74 |
|
75 |
|
76 | ## Full Documentation
|
77 |
|
78 | See [the phin documentation](https://ethanent.github.io/phin/).
|
79 |
|
80 | ## phin vs. the Competition
|
81 |
|
82 | <img src="https://pbs.twimg.com/media/DSLU_UcUEAI4bgc.jpg:large" alt="Request is over 6MB in size. phin is just 25KB in size."/>
|
83 |
|
84 | phin is a very lightweight library.
|
85 |
|
86 | It contains all of the common HTTP client features included in competing libraries!
|
87 |
|
88 | Package | Size (KB) | Dependencies<br />(Tree Count) | Size Comparison<br />(vs. phin)
|
89 | --- | --- | --- | ---
|
90 | request | 4,446 | [53](http://npm.anvaka.com/#/view/2d/request) | 444.6x
|
91 | superagent | 1,235 | [24](http://npm.anvaka.com/#/view/2d/superagent) | 123.5x
|
92 | got | 664 | [44](http://npm.anvaka.com/#/view/2d/got) | 66.4x
|
93 | snekfetch | 107 | [0](http://npm.anvaka.com/#/view/2d/snekfetch) | 10.7x
|
94 | phin | 10 | [1](http://npm.anvaka.com/#/view/2d/phin) | 1x |
\ | No newline at end of file |