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 🙏

© 2025 – Pkg Stats / Ryan Hefner

go-n-fetch

v2.0.1

Published

This project is a web request abstraction module that aims to reduce repetition

Readme

tested with jest jest

GoFetch

This project is a web request abstraction module that aims to reduce repetition

Installation

  • npm install go-n-fetch --save
  • yarn add go-n-fetch

For older browsers you can use promise-polyfill If you transpile your code be sure to use the corresponding fetch polyfills

Migration from v1 to v2

The usage is the same but for browser you need to change the import from go-n-fetch to go-n-fetch/browser

Usage

Fetch usage is almost exactly the same, you can prefill data and add behavior before and during the fetch request

Pre-filled request parameters

This will provide pre-filled request parameters to every subsequent call

import GoNFetch from 'go-n-fetch/browser'
// Pre-filling header data for authentication purposes
const goNFetch = GoNFetch({
  baseUrl: 'http://blog/api',
  headers: { "my-token": "super-secret-n-serialized-token" },
})

Options are:

  • baseUrl: Prefixes

Method calls

There are pre-filled methods that will ignore the request.method, usage is the same that fetch in every other aspect

GET

const posts = await goNFetch.get(`${url}/posts`).then(response.json())

POST

const newPost = { content: 'Lorem Ipsum', author: 'Dolor sit' }
const posts = await goNFetch.post(`${url}/posts`, { body: JSON.stringify(newPost) })

Supported verbs are:

  • GET
  • POST
  • PUT
  • DELETE
  • PATCH

IMPORTANT: the method parameters comes in UPPERCASE

Middlewares

You can register middlewares that intercept method calls before or after the fetch actual execution.

Provided events:

  • OnBeforeRequest
  • OnFetchFulfilled
  • OnFetchError

You can add middlewares using the register method

import GoNFetch from 'go-n-fetch/browser'
const goNFetch = GoNFetch({
  baseUrl: 'http://blog/api',
  headers: { "content-type": "application/json; charset=utf-8" },
})

// Create a middleware for body to be always stringified and a custom error log
goNFetch.register({
  // Middleware that serializes the body into a JSON string
  OnBeforeRequest: [async (request) => {
    if (request.body && request.method === 'POST' || request.method === 'PUT') {
      request.body = JSON.stringify(request.body)
    }
    return request
  }],
  OnFetchError: [async (error) => console.error(error)]
})

const newPost = { content: 'Lorem Ipsum', author: 'Dolor sit' }
// Every subsecuent call is simplified
const posts = await goNFetch.post('/posts', { body: newPost })

Middlewares are executed per event, in order of registration

Node Compatibilty

For Node implementation you need to install the optional dependency got and invoke it as documented in the library itself.