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

api-fetch-wrapper

v1.0.3

Published

Custom class to handle api requests and responses.

Readme

api-fetch-wrapper

This is a small wrapper to handle custom responses from your server. The package automatically adds an auth header to all your requests - it fetches the auth token from Async Storage (It's not secure. I recommend using rn-secure-storage). If the token is expired, it can send a refrsh request and then re-send the original request. You can also define your own functions based on the server's response.

Example scenario

Every time you get EXPIRED_TOKEN, you want to send a refresh_token request, and then re-send the original request - but not more than 3 times.

Installation

npm install api-fetch-wrapper

Usage

import Fetch from "api-fetch-wrapper"

const handleInvalidToken = json => {
	// do something
}

const storeFunction = async (key, value = "") => {
	/* the library sends the keys you define in params */
	if (value == "") {
		// get value
		return await AsyncStorage.getItem(value)
	}
	// set value
	return await AsyncStorage.setItem(key, value)
}

const fetchService = new Fetch(
	"https://example.com",
	{
		// params: the params the server expects / returns, and the keys to send to storeFunction
		auth_token: "auth_token", // auth token param in server response
		refresh_token: "refresh_token", // POST param for refreshing token
		error: "message" // if an error occurs, what's the name of the param the server returns? {"message": "ERROR MESSAGE"}
	},
	storeFunction, // function to handle get / set tokens
	{
		EXPIRED_TOKEN: "_handleExpiredToken", // built in in class
		INVALID_TOKEN: handleInvalidToken
	},
	2, // maximum requests to be sent
	"login/refresh_token" // refresh token endpoint
)

try {
	const resp = await fetchService.fetch("/endpoint", {
		method: "POST",
		body: {
			param: "hello world"
		}
	})

	// resp.json and resp.status
} catch (error) {
	// error.message is either an error from your server (if you defined params.error)
	// or a default error
}