npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

farfetch

v0.9.0

Published

Fluent API for window.fetch

Downloads

282

Readme

Farfetch

Build Status

Pompous, functional, and fluent interface for the Fetch API, inspired by SuperAgent.

Install

$ npm install farfetch

Usage

import farfetch from "farfetch";

farfetch
  .get("https://api.github.com/users/reu")
  .then(res => res.json())
  .then(console.log);

Plugins

As SuperAgent, Farfetch can be extended via plugins:

import farfetch, { prefix, responseLogger } from "farfetch";

farfetch
  .use(prefix("https://api.github.com"))
  .use(responseLogger())
  .get("/users/reu")
  .then(res => res.json())
  .then(console.log);

Available plugins

Delay

Delays a request for time milliseconds (aka poor man's throttle).

import farfetch, { delay } from "farfetch";

// Delays the request for 5 seconds
farfetch
  .use(delay(5000))
  .get("http://example.org")
  .end();

Prefix

Adds a prefix to the URL. This is quite handy for creating REST API clients.

import farfetch, { prefix } from "farfetch";

// This will issue a GET request to http://example.org/api/v1/test
farfetch
  .use(prefix("http://example.org/api/v1"))
  .get("/test")
  .end();

Note that as Farfetch never mutates the requests, we can freely reuse partial applied requests.

import farfetch, { prefix } from "farfetch";

// A "partial applied" request to the Github API
const github = farfetch
  .use(prefix("https://api.github.com"))
  .set("Authorization", "token 123mytoken");

// Issue two different requests to the Github API
const user = github.get("/users/reu").end();
const repo = github.get("/repos/reu/farfetch").end();

Request logger

A logger that logs the method and the url right before the request is made.

import farfetch, { requestLogger } from "farfetch";

// This will log "GET http://example.org"
farfetch
  .use(requestLogger())
  .get("http://example.org")
  .end();

// You can also change the logger
import winston from "winston";

farfetch
  .use(requestLogger(winston))
  .get("http://example.org")
  .end();

Response logger

A logger that logs the method, url, status code and response time of a request.

import farfetch, { responseLogger } from "farfetch";

// This will log "GET http://example.org 200 12ms"
farfetch
  .use(requestLogger())
  .get("http://example.org")
  .end();

// You can also change the logger
import winston from "winston";

farfetch
  .use(responseLogger(winston))
  .get("http://example.org")
  .end();

Developing plugins

A plugin is just a function that receives a request and returns a new one:

import farfetch from "farfetch";

const contentType = contentType => req =>
  req.method == "POST" || req.method == "PUT" ?
    req.set("Content-Type", contentType) :
    req;

const serializeJSON = req =>
  req.headers["Content-Type"] == "application/json" ?
    { ...req, body: JSON.stringify(req.body) } :
    req;

farfetch
  .use(contentType("application/json"))
  .use(serializeJSON)
  .post("http://example.org/users")
  .send({ actress: "Sasha" })
  .end();

If a plugin needs to change how a request will be made, it can redefines the execute function. For instance, this is how the delay plugin works:

// First, let's define a function who provides a promise that resolves after some time
const wait = time => new Promise(resolve => setTimeout(resolve, time));

// Plugins receives the original `execute` function as the second argument
export const delay = (time = 1000) => (req, execute) => ({
  // Add all the properties of the original request
  ...req,

  // A new `execute` function that awaits some time before calling the original one
  execute: req => wait(time).then(() => execute(req))
});