1.2.0 • Published 5 years ago

@shangs/fetch v1.2.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

fetch

install

npm i @shangs/fetch --save-dev

useage

import fetchs from '@shangs/fetch';
let config = {
	mode: 'no-cors',
	credentials: 'same-origin',
	headers: {
		contentType: 'application/json',
		accept: 'application/json',
	}
	timeout: 5000
};
// GET
fetchs
	.get('http://localhost:3003/students', config)
	.then(response => {
		console.log(response);
	})
	.catch(e => {
		console.log(e);
	});

fetchs
	.get('http://localhost:3003/students', {params: {name: 'Lily'}}, config)
	.then(response => {
		console.log(response);
	})
	.catch(e => {
		console.log(e);
	});

// POST
fetchs
	.post(' http://localhost:3003/students', data, config)
	.then(response => {
		console.log(response);
	})
	.catch(e => {
		console.log(e);
	});
// interceptors
fetchs.interceptors.request(config => {
	config = {
		timeout: 5000,
		mode: 'cors',
		credentials: 'include'
	};
	return config;
});

fetchs.interceptors.response(
	reponse => {
		return reponse;
	},
	err => {}
);
1.2.0

5 years ago

1.1.3

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago