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

fd-fetch-wrapper

v0.3.2

Published

Simple wrapper around fetch function to manage in a simple way the errors from BE using http status code

Downloads

17

Readme

Simple wrapper around fetch function to manage in a simple way the errors from BE using http status code

Usage

  1. Installation
fd-fetch-wrapper
  1. Import
import { FetchWrapper } from 'fd-fetch-wrapper';
  1. Create an instance of FetchWrapper
 const runner = new FetchWrapper(apiVersion, labels, status_401_403);

Where

  • apiVersion: optional parameter that can be used when we have different api version on our server, a parameter named 'api-version' will be added to the header

  • labels: optional parameter used to let you choose the message to show at FE for common error

static labels = {
   errorGeneric: 'Sorry we have errors on the remote server',
   errorServerNotAvailable: 'Server not available',
   errorSessionExpired: 'Your session has expired, please login.',
};
  • status_401_403: this is a callback function with no parameters that can be used to let you logout the user
  1. Avaliable methods
delete = (url, params, token, isFile = false, isBlob = false)

get = (url, token, params, isFile = false, isBlob = false) 

post = (url, params, token, isFile = false, isBlob = false, additionalParams = [])

put = (url, params, token, isFile = false, isBlob = false)

Sample

You can find this code in github, App.js of this repository

function App() {

    function status_401_403() {
        alert("Log Out");
    }

    const runner = new FetchWrapper(null, null, status_401_403);

    function onClick() {
        runner.get('http://localhost:61419/weatherforecast').then(response => {
            alert(response);
        }).catch(errorMessage => {
            if (errorMessage)
                alert(errorMessage);
        });

        runner.post('http://localhost:61419/weatherforecast', null, null, false, false, [{ namme: 'nome', value: 123 }]).then(response => {
            alert(response);
        }).catch(errorMessage => {
            if (errorMessage)
                alert(errorMessage);
        });
    }

    return (
        <React.Fragment>
        <button onClick={onClick}>Fetch Test</button>
        </React.Fragment>
    );
}

Available Scripts

In the project directory, you can run:

npm start

Runs the Demo app in the development mode. Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits. You will also see any lint errors in the console.

npm run distribute

Builds (made for windows) the app for production to the dist folder. It correctly bundles the React component.

npm publish

Publish the dist on npmjs.

License

MIT