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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zachacious/fetchy

v1.0.0

Published

A simple fetch utility for client-side Javascript. Supports GraphQL, retries and events.

Downloads

2

Readme

Fetchy

A modern client-side fetch utility for fetching API's in Javascript. Under the hood, Fetchy is a simple wrapper around fetch. I found myself reusing a set of fetch wrappers and decided to formalize them as their own module on NPM

Install

NPM:

npm install @zachacious/fetchy --save-dev

Yarn:

yarn add @zachacious/fetchy --dev

Features

  • Handles error catching and returns a nice easily consumeable object
{
    error: '', // Error message(String) or null
    response: {} // The fetched response or null
}
  • Supports GraphQL
  • Supports retries. Set # of retries and the delay between retries.
  • Supports events. You can subscribe to a fetchy request and listen for responses

Future Features

  • Support caching responses in IndexedDB
    • Support loading cached data then rehydrating in the background
  • Support Node

Usage

// Import the module
import fetchy from "fetchy";

// API
Fetchy(options) // api or graphql request
Fetchy.subscribe(String name, Function callback); // subscribe to a fetch
Fetchy.subscribeOnce(String name, Function callback); // subscribe to a fetch for one time only
Fetchy.unsubscribe(String name, Function callback); // unsubscribe from a fetch

// Available options
{
    url: String, // The url to fetch
    name: String, // Used for event subscriptions
    retries: Number, // Number of retries to attempt,
    retryDelay: Number, // Delay between retries(ms)
    httpOptions: {
        Fetch options here
        ...such as method, headers, body, etc
    },
    query: String, // GraphQL query
    variables: {} // GraphQL variables
}

Example

import fetchy from "@zachacious/fetchy";

// Subscribe Once
fetchy.subscribeOnce("RestAPIFetch", function (data) {
  console.log("RestAPIFetch Callback", data);
});
// Subscribe - listen to all calls
fetchy.subscribe("GraphQLFetch", function (data) {
  console.log("GraphQL Callback", data);
});

// Simple rest api fetch
const response = await fetchy({
  name: "RestAPIFetch",
  url: "http://fakeapi.jsonparseronline.com/profile/",
  retries: 5,
  retryDelay: 1000,
});

// GraphQL fetch
fetchy({
  name: "GraphQLFetch",
  url: "https://api.mocki.io/v2/c4d7a195/graphql",
  retries: 5,
  retryDelay: 1000,
  httpOptions: {
    method: "POST",
  },
  query: `
    query($id: String) {
        user(id: $id) {
            id
            name
            email
        }
    }
`,
  variables: {
    id: "Hello World",
  },
}).then(function (data) {
  console.log("GraphQL fetch.then");
});

Development

  • Clone the repo
  • cd into the root directory

Dependencies

 npm install // Install dependencies

Test

npm test // run tests

Lint

npm run lint // run linting

Develop & Watch

npm run dev // build dev version

Build

npm run build // build production version

demo

Run /demo/index.html and check the console to test the build

Maintainence

This project shouldn't require a lot of maintainence, but I'll do my best to keep things updated. If I fall behind, feel free to give me a swift kick in the a$$. In the mean time, feel free to pitch in and submit a PR or an issue.