首页
学习
活动
专区
圈层
工具
发布

微服务架构设计 第八步: 设计微服务对外 REST API

2016.9.22, 北京, Ken Fang

开发与测试人员协作完成了: 微服务对外需提供的方法 (API) 后, 开发与测试人员便需继续协作, 将微服务对外需提供的方法 (API), 设计成 REST API。

将微服务对外需提供的方法 (API), 设计成 REST API 的主要步骤如下:

1. 将微服务中代表某个单一业务概念的实体, 识为 “Resource”。并分析 Resource 间的关系。

Resource 间的关系

Independent

在没有其他的 Resources 存在下, 也能独立存在的 Resources。

Dependent

一定要所依赖的父 Resources 存在, 才能存在的 Resources。

Associative

Resources 间是互相独立存在的, 但, 彼此间存在著 “包含” 的关系; 某个 Resource 所需额外的 Properties, 只需 Link 到另一个 Resource。

2. 将微服务中代表某个单一业务概念的实体, 对外需提供的方法 (API), 对映到 Http 的方法。

API Modeling Actions

Typical HTTP Verb

List, Search, Match, View All

GET a resource collection

GET /{collection name}

Show, Retrieve, View

Get a resource

GET /{collection name}/{id}

Create, Add

POST create a resource

POST /{collection name}

Replace

PUT update a resource collection

PUT /{collection name}

Update

PUT update a resource

PUT /{collection name}/{id}

Delete All, Remove All, Clear, Reset

DELETE delete a resource collection

DELETE /{collection name}

Delete, Remove

DELETE delete a resource instance

DELETE /{collection name}/{id}

3.       依照由步骤 1, 所分析出 Resource 间的关系, 与由步骤 2, 所对映出的 Http 的方法, 设计出 Resource 的 Endpoint。

4.       依照步骤 3, 所设计出 Resource 的 Endpoint, 设计出 Http 的 Response Codes。

SaveSaveSaveSaveSaveSaveSaveSave

举报
领券