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

es6-api-wrapper

v0.0.1

Published

A basic ES6 API class that wraps the fetch function and allows for a more dynamic and robust interface to interact with any API - easily extendable and mighty flexible.

Readme

ES6 API Wrapper - About

A basic ES6 API class that wraps the fetch function and allows for a more dynamic and robust interface to interact with any API - easily extendable and mighty flexible.


What issues does this solve?

If you're wanting to interact with a complex API you'll want to make your API calls as structured and flexible as possible, this wrapper aims to solve that issue.

Simply extendable and suited for your API's needs, you can implement more complex functionality or simply use what's currently available.

How do I use it?

A demo implementation can be found in this projects index.html file.

Constructing the wrapper

To construct the API wrapper, you'll need to provide a host url (the API's domain), an object of endpoints and if you desire, a response type (Content-Type).

Endpoints format - Required properties

All endpoints should be listed in the endpoints object.

The endpoints object only requires two properties to function properly: url (string) and methods (array).

The url property must be the trailing endpoint that this endpoint should hit, for example if I wanted to hit a posts endpoint, my url property would be equal to /posts.

The methods property is an array of available HTTP methods that this endpoint has access to, for example my /posts endpoint has access to both POST and GET, so my methods property would be equal to ['POST', 'GET'].

API fetch format

To fetch data from an endpoint, you can call Api.fetch(method (string), endpoint (string), options (object)) - The fetch method returns a promise.

When fetching data you may pass options to each endpoint as you desire, however there are reserved properties which perform special functions, these being id (string), filter (object) and parent (string).

The id property will simply request the current endpoint with a resource identifier, for example http://myapi.com/posts/{id};

The filter property is an object containing anything you'd like to filter against this endpoint, creating a query string that implements your filters, for example http://myapi.com/posts?user=me.

The parent property is unique in that it can be used to retrieve a nested endpoint from a resource identifier. For example, if I have the endpoint /posts and that endpoint accepts a resource identifier such as /posts/{id}, but then also accepts a nested endpoint to retrieve comments like /posts/{id}/comments - the parent property will allow you to do this.

I would still create a new endpoint for my posts comments, however its parent would obviously be the endpoint that it nests under, in this case posts.