New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

isomorphic-fetch-http

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isomorphic-fetch-http

react fetch by isomorphic-fetch

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 方法,一般用于请求时的预检

Contributing

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

Keywords

FAQs

Package last updated on 16 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc