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

http-dub

v1.0.1

Published

A delightfully easy to use wrapper over the fetch API providing an easier way to create RESTful endpoints. Inspired by Phoenix frameworks "resources" macro. This project was initially created to simplify http calls in Vuex Actions, but can be used anywher

Downloads

5

Readme

http-dub

A delightfully easy to use wrapper over the fetch API providing an easier way to create RESTful endpoints. Inspired by Phoenix frameworks "resources" macro. This project was initially created to simplify http calls in Vuex Actions, but can be used anywhere.

Usage

import { http } from "http-dub"; 

const req = http("https://yoururl.com/:id);

NOTE The :id will be replaced by a provided argument during execution of one of the http methods, if the value isn't provided it's automatically removed.

Eg, GET Request

req.getReq({
  arguments: {
    // :id will be replaced with "user-id" in the url
    ":id": "user-id"
  },
  onResolve: () => {},
  onReject: (resp) => {<do something>}
})

Custom Request

If an extra route or http method is need besides the one that the library provides you can easily add with the extend method. The custom request is available on the otherReq method.

// req.extend(<funcName>, <method>, <path>)
req.extend("listUsers", "GET", "/list-users");

// The above added extension can now be called with
req.otherReq.listUsers();

NOTE The extended path is only available as a subpath of the original URL

List of all Supported request methods

getReq: "GET" request
postReq: "POST" request
putReq: "PUT" request
deleteReq: "DELETE" request
otherReq: custom requests added with the "extend" method

Each of the above takes an object as argument. The object properties are

arguments object; // Eg { :id: 5 }
body // body of fetch function
config RequestConfig; // The remaining properties of a fetch functions config excluding body
onResolve // callback function to handle successful request
onReject // callback function which gets the error returned from the request as the first argument 

Hooks

Hooks are provided that can run some code before or/and after a request is made

req
  .afterEach(() => {})
  .beforeEach(() => {})

If you like the project consider starring on Github. All contributions are welcome, Issues and PR.If you like the project consider starring it on Github