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

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 
主站蜘蛛池模板: 车险| 望都县| 两当县| 芦山县| 清水县| 怀化市| 且末县| 苏尼特右旗| 澄迈县| 聂荣县| 阿克苏市| 阳泉市| 长春市| 绥棱县| 武城县| 清苑县| 牙克石市| 清原| 仁怀市| 梁山县| 通许县| 辽中县| 合阳县| 文昌市| 江阴市| 满洲里市| 南投县| 彭山县| 海盐县| 甘肃省| 安徽省| 瑞丽市| 高碑店市| 南投县| 庐江县| 大理市| 辽中县| 上林县| 高雄县| 乌拉特后旗| 若尔盖县|