data-manager-x
v0.8.1
Published
A Light-Weight Http Library To Fetch Data And Manager Data
Downloads
2
Maintainers
Readme
data-manager-x
A Light-Weight Http Library To Fetch Data And Manager Data
Installation
npm install data-manager-x --save
or
yarn add data-manager-x
Usage
GET
import dm from 'data-manager-x';
async loadDataByGET() {
const res = await dataManager('http://localhost:3000/list');
}
// or with params
async loadDataByGETComplex() {
const res = await dataManager({
method: 'GET',
url: `http://localhost:3000/list`,
params: {
id: '1087139'
},
});
}
POST (Upload File With FormData)
import dm from 'data-manager-x';
async loadDataByPOST() {
const DOM = document.querySelector('#avatar');
const fileData = new FormData();
fileData.append('avatar', DOM.files[0]);
const res = await dataManager({
method: 'POST',
url: `http://localhost:3000/upload`,
data: fd,
onUploadProgress: function (event) {
console.log('event: ', event);
}
});
}