1.3.8 • Published 1 year ago

@yqg/resource v1.3.8

Weekly downloads
22
License
MIT
Repository
-
Last release
1 year ago

@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
1.3.8

1 year ago

1.2.5

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1-alpha

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.6

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago