🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

fetch-default

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-default

Add global default properties for the web fetch

Source
npmnpm
Version
1.0.9
Version published
Weekly downloads
103
-29.93%
Maintainers
1
Weekly downloads
 
Created
Source

fetch-default

为web端fetch添加全局默认属性(Add global default properties for the web fetch)

安装(install)

npm i fetch-default --save

使用(use)

require('fetch-default');

//es
import 'fetch-default';

通过default为所有请求添加前缀

	fetch.default({
		uriPrefix: '/api'
	});

	//default request /api/async/get
	
	fetch('/async/get', {
    	method: 'GET'
		})
		.then((response) => response.json())
		.then((json) => console.log(json));
		

通过default设置默认optoin

	fetch.default({ 
    method: 'GET',
   	headers: myHeaders,
   	mode: 'cors',
   	cache: 'default' 
   	...
});
	/*
	默认所有请求都配置
  method: 'GET',
		headers: myHeaders,
 	mode: 'cors',
 	cache: 'default'
 	...
*/
    
	fetch('/async/get', {
    	method: 'POST'//覆盖默认设置后请求为post(covering)
		})
		.then((response) => response.json())
		.then((json) => console.log(json));
		
		
		

Community

github npm

Keywords

fetch、web、global、default

FAQs

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