Socket
Socket
Sign inDemoInstall

phin

Package Overview
Dependencies
2
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    phin

The ultra-lightweight Node.js HTTP client


Version published
Weekly downloads
1.2M
increased by2.38%
Maintainers
1
Install size
51.7 kB
Created
Weekly downloads
 

Package description

What is phin?

The phin npm package is a lightweight HTTP client designed for simplicity and minimalism. It is used for making HTTP requests from Node.js environments. It supports promises and can handle various types of requests such as GET, POST, and more.

What are phin's main functionalities?

Simple HTTP GET requests

This code sample demonstrates how to perform a simple HTTP GET request to a specified URL using phin.

const phin = require('phin')

phin('https://example.com', (err, res) => {
  if (err) throw err
  console.log(res.body)
})

HTTP POST requests with JSON

This code sample shows how to perform an HTTP POST request with JSON data using phin.

const phin = require('phin')

const options = {
  url: 'https://example.com/post',
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  data: { key: 'value' }
}

phin(options, (err, res) => {
  if (err) throw err
  console.log(res.body)
})

Promisified HTTP requests

This code sample illustrates how to use phin with promises to make asynchronous HTTP requests.

const phin = require('phin').promisified

async function makeRequest() {
  try {
    const res = await phin('https://example.com')
    console.log(res.body)
  } catch (err) {
    console.error(err)
  }
}

makeRequest()

Other packages similar to phin

Readme

Source

phin logo


The lightweight Node.js HTTP client

Full documentation | GitHub | NPM

Deprecated

This package is deprecated and should not be used. Please see #91 for more information.

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:

PackageSize
requestrequest package size
superagentsuperagent package size
gotgot package size
axiosaxios package size
isomorphic-fetchisomorphic-fetch package size
r2r2 package size
node-fetchnode-fetch package size
phinphin package size

Keywords

FAQs

Last updated on 11 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc