官术网_书友最值得收藏!

Naming for RPC

With RPC you do not have the luxury of using HTTP verbs to confer the intent of the API, for example, you have the collection users. With an HTTP API you would be able to split up the various actions using GET, POST, DELETE, and so on. This is not possible with an RPC API and you need to think in the same way as if you were writing methods inside your Go code, so for example:

GET /v1/users 

The preceding code might be written as an RPC method as follows:

Users.v1.Users 
GET /v1/users/123434

Alternatively, it might be written as an RPC method as follows:

Users.v1.User 

Sub collections become a little less semantic, whereas in a RESTful API you would be able to do the following:

GET /v1/users/12343/permissions/1232 

You cannot do this with an RPC API and you must explicitly specify the method as a separate entity:

Permissions.v1.Permission 

The method name also needs to infer the action that the API is going to perform; you cannot rely on the use of HTTP verbs, so in the instance that you have a method that can delete a user you would have to add the delete verb into the method call, for example:

DELETE /v1/users/123123 

The preceding code would become:

Users.v1.DeleteUser 
主站蜘蛛池模板: 隆安县| 丹江口市| 常宁市| 哈尔滨市| 乐平市| 吴川市| 张家界市| 卢龙县| 平和县| 淮安市| 盘山县| 赤城县| 西乌珠穆沁旗| 清镇市| 天柱县| 宜宾市| 临清市| 故城县| 宁夏| 沙河市| 濮阳县| 鹤壁市| 辽阳县| 新兴县| 鹿泉市| 京山县| 隆化县| 浦江县| 佛山市| 石景山区| 新化县| 安西县| 合阳县| 寿宁县| 麟游县| 元氏县| 邯郸县| 青田县| 汉川市| 三明市| 黄冈市|