Based on axios to implement a network request library that can use decorators, refer to Nest
Another way to manage APIs in a project, maybe expand to other more interesting experiments?
pnpm install fashion-axios -s
Before starting, you need to make sure that experimentalDecorators
and emitDecoratorMetadata
are set to true in tsconfig.json.
refer to playground
Declare configuration before loading your program
import { defineConfig } from 'fashion-axios'
defineConfig({
baseURL: '',
headers: {}
})
defineConfig([
{
baseURL: '',
headers: {}
},{
name:"",
baseURL: '',
headers: {}
}
])
import { Api } from 'fashion-axios'
@Api('/user')
class UserApi {
}
import { Api } from 'fashion-axios'
@Client('name')
@Api('/user')
class UserApi {
}
import { Api, Get, Post } from 'fashion-axios'
@Api('/user')
class UserApi {
@Post('/add')
add(): Type { }
@Get('/list')
list(): Type { }
// ...more
// @Put @Delete
}
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 { }
}