API 命名规范

背景

项目是使用Spring Cloud作为服务治理框架,内部接口和外部接口都通过一个应用服务来提供,所以需要在API Code上面体现当前接口具体的使用场景。

应用服务层面的API命名规范

/ API使用渠道关键字 / ControllerName / ActionName

场景

1、提供给外部渠道使用(PC、app、H5、第三方合作平台)

  • app:/app/refund/create
  • 运营系统:/operation/refund/create
  • 商家端:/merchant/refund/create
  • 依次类推 xxx渠道:/xxx/controllerName/actionName

2、内部应用服务互相调用(Service To Service)

  • 服务与服务之间:/inner/refund/create

同时因未完全遵循restful的标准,在 ControllerName 和 ActionName 的命名上尽量遵循如下规则
ControllerName :模块名称
ActionName :具体的操作名称包含对资源的操作类型如(getXxxx、createXxx、updateXxx、deleteXxxx、login、logout)、或者业界常用单词具备通用理解性如(login、logout)

以上的应用API命名最终在经过zuul层之后还会包含应用服务识别关键字,所以对于调用端来说最终的APICode格式如下

/ 服务关键字 / API使用渠道关键字 / ControllerName / ActionName

示例 /user/operation/base/login 、/user/operation/base/getUserList

PS:
同时zuul会对一下api进行过滤,禁止对外访问,如内部之间调用请通过Feign Client进行调用

ignored-patterns: /**/admin/**,/**/internal/**,,/**/inner/**

你可能感兴趣的:(API 命名规范)