这一章 讲的是 请求方法 这一部分可以参考 控制器-请求方法

Midway 还提供了其他的装饰器, @Get@Post@Put()@Del()@Patch()@Options()@Head()@All() ,表示各自的 HTTP 请求方法。

接下来我们看下源码是如何针对这些方法进行定义

1. 请求方法的定义

  1. export const RequestMethod = {
  2. GET: 'get',
  3. POST: 'post',
  4. PUT: 'put',
  5. DELETE: 'delete',
  6. PATCH: 'patch',
  7. ALL: 'all',
  8. OPTIONS: 'options',
  9. HEAD: 'head',
  10. };
  11. /**
  12. * Routes HTTP POST requests to the specified path.
  13. */
  14. export const Post = createMappingDecorator(RequestMethod.POST);
  15. /**
  16. * Routes HTTP GET requests to the specified path.
  17. */
  18. export const Get = createMappingDecorator(RequestMethod.GET);
  19. /**
  20. * Routes HTTP DELETE requests to the specified path.
  21. */
  22. export const Del = createMappingDecorator(RequestMethod.DELETE);
  23. /**
  24. * Routes HTTP PUT requests to the specified path.
  25. */
  26. export const Put = createMappingDecorator(RequestMethod.PUT);
  27. /**
  28. * Routes HTTP PATCH requests to the specified path.
  29. */
  30. export const Patch = createMappingDecorator(RequestMethod.PATCH);
  31. /**
  32. * Routes HTTP OPTIONS requests to the specified path.
  33. */
  34. export const Options = createMappingDecorator(RequestMethod.OPTIONS);
  35. /**
  36. * Routes HTTP HEAD requests to the specified path.
  37. */
  38. export const Head = createMappingDecorator(RequestMethod.HEAD);
  39. /**
  40. * Routes all HTTP requests to the specified path.
  41. */
  42. export const All = createMappingDecorator(RequestMethod.ALL);

我们根据上面的方法 定义可以看到 其实我们用到的各种各样不同类型的方法