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

flux-fetch

v0.1.1

Published

A wrapper for fetch that makes it easier to send requests to Flux

Downloads

6

Readme

Flux Fetch

Installation

Install from the repo:

$ npm install --save flux-fetch

Import the package into your project:

// Using ES6 modules
import fluxFetch from 'flux-fetch';

// Using CommonJS modules
var fluxFetch = require('flux-fetch').default;

NOTE: This will place fetch, Request, Response, and Headers in your global context if they are not already there, e.g., if you are in Node.

Usage

fluxFetch(path, options)

Arguments

  1. path (String): The request URL
  2. options (Object = { fluxToken: String, ...others }): The custom options that you ultimately want to get sent to fetch, in addition to the defaults set by fluxFetch. For example:

fluxToken (String - required): The user's Flux CSRF token. Most likely, this is available as the flux_token cookie.

method (String - default: 'get'): The request's HTTP method

body (any): The request payload. If the content-type header is set to something other than application/json, this will be provided as is. Otherwise, it will be JSON-stringified. GET requests will fail if passed a body.

headers (Object): A Headers object. To access a specific header, you can use headers.get(header). Listing all headers is environment-specific, e.g., in Node you can use headers.raw() and in the browser you can iterate over the headers with for...of.

Returns

(Promise --> Object: { status: Number, statusText: String, headers: Object, body?: any }): A promise that resolves to the response. If the response fails (i.e., the status is < 200 or

= 300), it will reject with an error that has the same properties.

Suggested Use

You may want to make another wrapper on top of fluxFetch that is custom to your app's particular use case. This is particularly useful so that you don't always need to explicitly pass in the current user's Flux token, as well as for common error handling.

For example:

import cookie from 'js-cookie';
import fluxFetch from 'flux-fetch';

function request(url, options) {
  return fluxFetch(url, Object.assign({}, options, { fluxToken: cookie.get('flux_token') })
    .catch(handleRequestError);
}

function handleRequestError(error) {
  // e.g., check if the user is still logged in and send them back to lgoin if they're not
}

Development

  1. git clone [email protected]:fluxio/flux-fetch.git
  2. npm install
  3. npm run test:watch to run the tests on changes or npm test to run them once

Publishing a New Version

This assumes that dependencies have been installed with npm install.

  1. Increment the version in package.json using Semver
  2. npm run prepublish
  3. git add package.json && git commit -m 'Update to version <version>'
  4. git tag v<version>
  5. git push && git push --tags
  6. npm publish