0.0.3 • Published 2 months ago

phn v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

phn

A lightweight http client adapted from phin and centra.

install

npm i phn

usage

const phn = require("phn");

const res = await phn({
	url: 'https://example.org'
});

options

  • url - URL to request
  • method - HTTP method, default: GET
  • headers - HTTP headers object
  • query - Object to be added to url as query string
  • data - Request body; json, buffer or object containing form data
  • form - object containing form data
  • core - options passed on to http(s).request
  • parse - parse response body as json or string
  • followRedirects - follow redirects if true
  • maxRedirects - maximum number of redirects to follow, default: infinite
  • stream - return stream as res.stream instead of res.body
  • compression - handle compression, accept br, gzip and deflate
  • timeout - request timeout in milliseconds

stream

consume http response as stream

const phn = require("phn");

const stream = await phn({
	url: 'https://example.org/',
	compression: true,
	stream: true,
});

stream.pipe(/* ... */)

custom http(s) options

use a custom agent

const phn = require("phn");
const https = require("https");

const agent = new https.Agent({ keepAlive: true });

await phn({
	url: 'https://example.org/',
	core: { agent },
});

unpromisified

get a classic callback interface

const phn = require("phn").unpromisified;

phn('https://example.org/', (err, res) => {
	if (!err) console.log(res.body);
});

defaults

set options for any subsequent request

const phn = require("phn").defaults({
	method: 'POST',
	parse: 'json',
	timeout: 2000
});

const res = await phn('https://example.org/')

comparison

phn is tiny and comes with no dependencies.

PackageSize
node-fetchnode-fetch package size
axiosaxios package size
requestrequest package size
superagentsuperagent package size
undiciundici package size
gotgot package size
isomorphic-fetchisomorphic-fetch package size
r2r2 package size
slim-fetchslim-fetch package size
phinphin package size
phnphn package size

license

MIT

acknowledgement

phn is a fork of phin and centra by Ethan Davis.

0.0.1

2 months ago

0.0.3

2 months ago

0.0.2

2 months ago

0.0.0

2 months ago