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

isomorphic-fetch-http

v3.0.0

Published

react fetch by isomorphic-fetch

Downloads

14

Readme

isomorphic-fetch-http

NPM version NPM downloads

Install

npm install isomorphic-fetch-http --save

Usage

import { http } from 'isomorphic-fetch-http'

http.setup({
  cookies: true,
});

return http.get('url', param, header);

Options

setup

全局配置

prefix

请求 url 前缀

headers

配置请求头

cookies

是否携带cookies

filter

过滤函数,发生在请求发出之前,可以对url, headers,fetch option进行更改,类型为 Promise function。

http.setup({
  filter: data => new Promise((resolve, reject) => {
    // 获取
    const { url, headers, option } = data;
    
    // 修改
    const newHeaders = {
      ...headers,
      token: 'zhnagsan'
    };
    
    // 返回
    resolve({ url, headers: newHeaders, option });
  })
});

callback

回调数据函数,对请求成功获取到的数据进行预处理

http.setup({
  callback: data => {
    const { status, data, messgae } = data;
    if (status) {
      return data;
    } else {
      throw new Erroe(message);
    }
  }

get

get 方法,一般用于数据查询

return http.get('/get', {currentPage: 1}, {token: 'zhangsan'}); // 此处的headers优先级最高

post

post 方法,一般用于数据提交

return http.post('/add', {username: 'zhangsan'});

put

put 方法,一般用于数据修改

return http.put('/update/1', {username: 'lisi'});

delete

delete 方法,一般用于数据删除

return http.put('/delete/1');

json

请求头 "Content-Type" 为 "application/json" 的 post 方法

return http.post('/add', {username: 'zhangsan'});

options

option 方法,一般用于请求时的预检

Links

Contributing

You can submit any ideas as pull requests or as a Github issue.