@yqg/resource
TypeScript icon, indicating that this package has built-in type declarations

1.3.8 • Public • Published

@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

Readme

Keywords

Package Sidebar

Install

npm i @yqg/resource

Weekly Downloads

76

Version

1.3.8

License

MIT

Unpacked Size

42.7 kB

Total Files

14

Last publish

Collaborators

  • devmsg
  • hongweihu
  • iuwoo
  • ykboluo
  • yqg-owner
  • jxlnljt
  • yulodl
  • center620
  • guxiaodai
  • northseacoder
  • wenxiujiang
  • zzj5470816
  • yyh_
  • szll
  • zhayoyang