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

rester-js

v0.2.1

Published

**Rester.js** is a RESTful HTTP client wrapper for the fetch API built with TypeScript. It ships ready for use with JSON APIs.

Downloads

3

Readme

Rester.js

Rester.js is a RESTful HTTP client wrapper for the fetch API built with TypeScript. It ships ready for use with JSON APIs.

Purpose

Apps that rely on RESTful APIs tend to repeat themselves when using API clients, like fetch(). Rester.js provides a layer over the fetch API that makes it easy to setup default behavior between calls.

Usage

Here is an example of how Rester.js can be used:

import { RESTfulClient } from 'rester-js'

// This will become the basis of all calls made with the instance of the RESTfulClient
const root = 'https://myapi.com/'

// Initialize the client with default values
const rester = new RESTfulClient(root, {
  // applies the Authorization header. Can also be set under a header secion in fetchOptions.
  authorization: 'Bearer jwttoken.string.forauth',

  // applies the Content-Type header. Can also be set under a header secion in fetchOptions.
  contentType: 'application/json',

  // will run after every successful request. Use the errorHandler option to run actions after failed requests.
  resolver: async res => await res.json(),

  // Options passed to the fetch api.
  // May be overwritten by authorization, contentType, or any options in the individual request.
  fetchOptions: {
    redirect: 'follow'
  }
});

// sends GET to "https://myapi.com/example?id=1&name=resource".
rester.get('example', { id: 1, name: 'resource' });

// sends POST request to "https://myapi.com/example" (fixes repeat slashes in route).
rester.post('/example', { id: 2, name: 'new resource' });

// sends PUT request to "https://myapi.com/example/3".
rester.put('example/3', { name: 'updated resource' });

// sends DELETE request to "https://myapi.com/example/4".
rester.delete('example/4');

Or, you might create a mapping of RESTfulClients based on endpoints:

const endpointMapping = {
  myApp: new RESTfulClient(root, {
    // ...options...
  }),
  otherApp: new RESTfulClient('https://google.com', {
    // ...options...
  })
};

// sends GET to "https://myapi.com/example/5".
endpointMapping.myApp.get('example/5');

Each method also accepts an options object for the fetch API:

rester.post('example', {name: 'resource' }, { 
  cache: 'no-cache',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})