Skip to content

yzydeveloper/fashion-axios

Repository files navigation

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 { }
}

About

Use decorators to create API modules in projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published