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

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-82.35%
Maintainers
1
Weekly downloads
 
Created
Source

isomorphic-fetch-http

NPM version NPM downloads

Install

npm install isomorphic-fetch-http --save

Usage

Use prebuilt bundle

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

// isomorphic-fetch-http 要求数据返回格式为
{
  status: true,            // 请求状态 true/false
  code: 'INVALIDError',    // 发生特定异常返回的错误码 与 exception 对应
  data: {} / []            // 请求状态为 true 时返回的数据体 
  message                  // 请求状态为 false 时返回的详细错误信息
}

// 全局配置
http.setup({
  prefix: '/api',               // url 前缀
  header: {},                   // 自定义请求头
  filter: {                     // 自定义过滤器 before 发生在请求执行之前 after 发生在请求执行之后
    before: () => false,
    after: () => false
  }
  exception: ['INVALIDError']   // 自定义捕获类型
});

http.setHeader({                // 覆盖/新增 请求头 
  token: ''
})

// get方法 一般用于查询
// @param {Object} param
// @param {Object} header
// @return {Object} {status, data, message}
return http.get('url', param, header);

// post方法 一般用于数据提交
// @param {Object} param
// @param {Object} header
// @return {Object} {status, data, message}
return http.post('url', param, header);

// put方法 一般用于数据修改
// @param {Object} param
// @param {Object} header
// @return {Object} {status, data, message}
return http.put('url', param, header);

// delete方法 一般用于数据删除
// @param {Object} param
// @param {Object} header
// @return {Object} {status, data, message}
return http.delete('url', param, header);

// json方法 本质是请求头为 "Content-Type": "application/json" 的post方法
// @param {Object} param
// @param {Object} header
// @return {Object} {status, data, message}
return http.json('url', param, header);

// option方法 本质是请求头为 "Content-Type": "application/json" 的post方法
// WARNING: 在isomorphic-fetch-http 1.0.0版本及以上版本,option方法已经由json方法代替,option方法将在1.1.0版本中去除
// @param {Object} param
// @param {Object} header
// @return {Object} {status, data, message}
return http.option('url', param, header);

// options方法 一般用于请求时的预检
// @param {Object} param
// @param {Object} header
// @return {Object} {status, data, message}
return http.options('url', param, header);

Contributing

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

Keywords

FAQs

Package last updated on 20 Jul 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