fashion-axios
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

fashion-axios

Based on axios to implement a network request library that can use decorators, refer to Nest

Purpose

Another way to manage APIs in a project, maybe expand to other more interesting experiments?

Install

pnpm install fashion-axios -s

Before starting, you need to make sure that experimentalDecorators and emitDecoratorMetadata are set to true in tsconfig.json.

Configure

refer to playground

Declare configuration before loading your program

import { defineConfig } from 'fashion-axios'

defineConfig({
    baseURL: '',
    headers: {}
})

defineConfig([
    {
        baseURL: '',
        headers: {}
    },{
        name:"",
        baseURL: '',
        headers: {}
    }
])

Class Decorator

@Api

import { Api } from 'fashion-axios'

@Api('/user')
class UserApi {

}

@Client

import { Api } from 'fashion-axios'

@Client('name')
@Api('/user')
class UserApi {

}

Request Decorator

import { Api, Get, Post } from 'fashion-axios'

@Api('/user')
class UserApi {
    @Post('/add')
    add(): Type { }

    @Get('/list')
    list(): Type { }

    // ...more
    // @Put @Delete
}

Param Decorator

import { Api, Get, Post, Body, Query } from 'fashion-axios'

@Api('/user')
class UserApi {
    @Post('/add')
    add(@Body() body: Type): Type { }

    @Post('/update/:id')
    update(
        @Path('id') id: Type
        @Body() body: Type
    ): Type { }

    @Get('/list')
    list(@Query() params: Type): Type { }
}

Package Sidebar

Install

npm i fashion-axios

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

82.4 kB

Total Files

6

Last publish

Collaborators

  • yzydeveloper