@yqg/resource
v1.3.8
Published
RESTful http resource based on axios.js
Downloads
59
Readme
@yqg/resource
axios based RESTful HTTP client for the browser and NodeJS
Install
Using npm:
npm install @yqg/resource
Using yarn:
yarn add @yqg/resource
Usage
// new fashion
// assign
import {assign, customGet, customPost, customPut, customPatch, CustomDelete,customHead, customOptions, CustomResource} from '@yqg/resource';
const api = {
urlPrefix: '/api/entity',
url: ':id',
getCustom: customGet('getCustom'),
postCustom: customPost('postCustom'),
postFormdata: customPost({url:'postFormdata', formData: true})
...
};
export default assign(api) as CustomResource<typeof api>;
// decorator
import Resource, {autobind, getMapping, postMapping...} from '@yqg/resource';
class Entity extends Resource {
urlPrefix = '/api/entity',
url = ':id',
@getMapping('getCustom')
async getCustom() {
}
...
}
export default new Entity();
// old school
import {create, CustomResource} from '@yqg/resource';
const api = {
urlPrefix: '/api/entity',
url: ':id',
getCustom: {
url: 'getCustom',
method: 'get'
}
postCustom: {
url: 'postCustom',
method: 'post'
},
postFormdata: {
url: 'postFormdata',
method: 'post',
formData: true
},
...
}
export default create(api) as CustomResource<typeof api>;
Caution
- FormData related is not compatible with NodeJS environment