这一章 讲的是 请求方法 这一部分可以参考 控制器-请求方法
Midway 还提供了其他的装饰器, @Get
、 @Post
、 @Put()
、 @Del()
、 @Patch()
、 @Options()
、 @Head()
和 @All()
,表示各自的 HTTP 请求方法。
接下来我们看下源码是如何针对这些方法进行定义
1. 请求方法的定义
export const RequestMethod = {
GET: 'get',
POST: 'post',
PUT: 'put',
DELETE: 'delete',
PATCH: 'patch',
ALL: 'all',
OPTIONS: 'options',
HEAD: 'head',
};
/**
* Routes HTTP POST requests to the specified path.
*/
export const Post = createMappingDecorator(RequestMethod.POST);
/**
* Routes HTTP GET requests to the specified path.
*/
export const Get = createMappingDecorator(RequestMethod.GET);
/**
* Routes HTTP DELETE requests to the specified path.
*/
export const Del = createMappingDecorator(RequestMethod.DELETE);
/**
* Routes HTTP PUT requests to the specified path.
*/
export const Put = createMappingDecorator(RequestMethod.PUT);
/**
* Routes HTTP PATCH requests to the specified path.
*/
export const Patch = createMappingDecorator(RequestMethod.PATCH);
/**
* Routes HTTP OPTIONS requests to the specified path.
*/
export const Options = createMappingDecorator(RequestMethod.OPTIONS);
/**
* Routes HTTP HEAD requests to the specified path.
*/
export const Head = createMappingDecorator(RequestMethod.HEAD);
/**
* Routes all HTTP requests to the specified path.
*/
export const All = createMappingDecorator(RequestMethod.ALL);
我们根据上面的方法 定义可以看到 其实我们用到的各种各样不同类型的方法