1.0.3 • Published 10 months ago
fashion-axios v1.0.3
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 -sBefore 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 { }
}1.0.3
10 months ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
3 years ago
0.1.0-beta.2
3 years ago
0.1.0-beta.1
3 years ago
0.1.0-beta.0
3 years ago