🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@yqg/resource

Package Overview
Dependencies
Maintainers
15
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yqg/resource

RESTful http resource based on axios.js

latest
npmnpm
Version
1.3.8
Version published
Weekly downloads
26
-25.71%
Maintainers
15
Weekly downloads
 
Created
Source

@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

Keywords

restful

FAQs

Package last updated on 18 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts