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

bitquest

v1.0.0

Published

Makes JSON requests with fetch easier, the Bitrock way!

Downloads

4

Readme

Bitquest Build Status

Makes writing JSON requests with fetch easier, in Bitrock style!

Bitquest is a tiny (0.5kb min/gz) fetch wrapper that can be used in the browser (IE11+) and Node.

Before

// POST /users
fetch('/users', {
  method: 'post',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Typicode',
    login: 'typicode',
  })
})
.then(function(response) {
  if (response.status >= 200 && response.status < 300) {
    return response.json()
  }
  throw new Error(response.statusText)
})
.then(function(json) {
  // ...
})

After

// POST /users
bitquest('/users').post({
  name: 'Typicode',
  login: 'typicode'
})
.then(function(json) {
  // ...
})

.get(), .put(), .patch() and .delete() methods are also available.

Installation

Bitquest is available on NPM.

Browser

npm install es6-promise whatwg-fetch # polyfills
npm install bitquest

Node

npm install node-fetch bitquest --save

Usage examples

import bitquest from 'bitquest';

const posts = bitquest('/posts')

//posts
posts.get()
posts.post({ title: 'Bitquest' })

//posts?category=javascript
posts.get({ category: 'javascript' })

//posts/1
posts(1).get()
posts(1).put({ title: 'Bitquest is simple' })
posts(1).patch({ title: 'Bitquest is simple' })
posts(1).delete()

const comments = posts('1/comments')

//posts/1/comments
comments.get()

//posts/1/comments/1
comments(1).get()

You can also pass fetch options to bitquest()

const posts = bitquest('/posts', fetchOptions)
const comments = posts('1/comments') // Will inherit fetchOptions

To catch errors

bitquest('/posts')
  .get()
  .catch(function(err) {
    console.log(err)
  })

To enable CORS

const request = bitquest('/', { mode: 'cors' })
const posts = request('posts')

To fetch plain text (for example, HTML views)

const request = bitquest('/', { responseAs: 'text' })
const posts = request('posts')

responseAs can be response, text or json (default)

To use bitquest in Node, you need to install node-fetch and configure fetchival to use it

const bitquest = require('bitquest')
bitquest.fetch = require('node-fetch')

Browser Support

Chrome | Firefox | IE | Opera | Safari | Edge --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | 11 ✔ | Latest ✔ | 6.1+ ✔ | Latest ✔ |

Forking fetchival

We forked the original project Fetchival because we liked the idea of using standard Fetch API with a thin layer on top of it to avoid boilerplate on projects, but we needed to have it fashioned on our code style & worfklow.

Notable changes from fetchival are:

  • the name
  • removed browser version (you can build it from source if you need it) and Bower package
  • main code refactored in Typescript with a bit more functional approach
  • tests have been refactored to Ava.js
  • add code linting with XO

License

MIT