UNPKG

3.01 kBMarkdownView Raw
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
13const p = require('phin')
14
15const res = await p('https://ethanent.me')
16
17console.log(res.body)
18```
19
20Note that the above should be in an async context! phin also provides an unpromisified version of the library.
21
22## Install
23
24```
25npm install phin
26```
27
28
29## Why phin?
30
31phin 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
33Also, 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
40Simple POST:
41
42```js
43await p({
44 url: 'https://ethanent.me',
45 method: 'POST',
46 data: {
47 hey: 'hi'
48 }
49})
50```
51
52## Unpromisified Usage
53
54```js
55const p = require('phin').unpromisified
56
57p('https://ethanent.me', (err, res) => {
58 if (!err) console.log(res.body)
59})
60```
61
62Simple parsing of JSON:
63
64```js
65// (In async function in this case.)
66
67const res = await p({
68 url: 'https://ethanent.me/name',
69 parse: 'json'
70})
71
72console.log(res.body.first)
73```
74
75## Default options
76
77```js
78const ppostjson = p.defaults({
79 'method': 'POST',
80 'parse': 'json',
81 'timeout': 2000
82})
83
84// In async function...
85
86const res = await ppostjson('https://ethanent.me/somejson')
87// ^ An options object could also be used here to set other options.
88
89// Do things with res.body?
90```
91
92
93## Full Documentation
94
95See [the phin documentation](https://ethanent.github.io/phin/).
96
97## phin vs. the Competition
98
99phin is a very lightweight library, yet it contains all of the common HTTP client features included in competing libraries!
100
101Here's a size comparison table:
102
103Package | Size
104--- | ---
105request | [![request package size](https://packagephobia.now.sh/badge?p=request)](https://packagephobia.now.sh/result?p=request)
106superagent | [![superagent package size](https://packagephobia.now.sh/badge?p=superagent)](https://packagephobia.now.sh/result?p=superagent)
107got | [![got package size](https://packagephobia.now.sh/badge?p=got)](https://packagephobia.now.sh/result?p=got)
108snekfetch | [![snekfetch package size](https://packagephobia.now.sh/badge?p=snekfetch)](https://packagephobia.now.sh/result?p=snekfetch)
109phin | [![phin package size](https://packagephobia.now.sh/badge?p=phin)](https://packagephobia.now.sh/result?p=phin)
\No newline at end of file