phin

3.7.1last stable release 1 year ago
Complexity Score
Low
Open Issues
24
Dependent Projects
170
Weekly Downloadsglobal
1,933,279

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

The lightweight Node.js HTTP client

Full documentation | GitHub | NPM

Deprecation warning

Some versions of this package are deprecated and shouldn’t be used. Be sure you are using a non-deprecated, supported version of the package.

Simple Usage

const p = require('phin')

const res = await p('https://ethanent.me')

console.log(res.body)

Note that the above should be in an async context! Phin also provides an unpromisified version of the library.

Install

npm install phin

Why Phin?

Phin is relied upon by important projects and large companies. The hundreds of contributors at Less, for example, depend on Phin as part of their development process.

Also, Phin is very lightweight. To compare to other libraries, see Phin vs. the Competition.

Quick Demos

Simple POST:

await p({
    url: 'https://ethanent.me',
    method: 'POST',
    data: {
        hey: 'hi'
    }
})

Unpromisified Usage

const p = require('phin').unpromisified

p('https://ethanent.me', (err, res) => {
    if (!err) console.log(res.body)
})

Simple parsing of JSON:

// (In async function in this case.)

const res = await p({
    'url': 'https://ethanent.me/name',
    'parse': 'json'
})

console.log(res.body.first)

Default Options

const ppostjson = p.defaults({
    'method': 'POST',
    'parse': 'json',
    'timeout': 2000
})

// In async function...

const res = await ppostjson('https://ethanent.me/somejson')
// ^ An options object could also be used here to set other options.

// Do things with res.body?

Custom Core HTTP Options

Phin allows you to set core HTTP options.

await p({
    'url': 'https://ethanent.me/name',
    'core': {
        'agent': myAgent // Assuming you'd already created myAgent earlier.
    }
})

Full Documentation

There’s a lot more which can be done with the Phin library.

See the Phin documentation.

Phin vs. the Competition

Phin is a very lightweight library, yet it contains all of the common HTTP client features included in competing libraries!

Here’s a size comparison table:

Package Size request superagent got axios isomorphic-fetch r2 node-fetch phin

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
4.90
Test Coverage
No Data
Follows Semver
Yes
Github Stars
576
Dependenciestotal
1
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute phin in your own private NPM registry

npm config set registry  https://npm.cloudsmith.com/owner/repo
Processing...
Done
npm install phin
Processing...
Done

64 Releases

NPM on Cloudsmith

Getting started with NPM on Cloudsmith is fast and easy.