- Building Microservices with Go
- Nic Jackson
- 212字
- 2021-07-15 17:28:16
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
- Web應(yīng)用系統(tǒng)開發(fā)實(shí)踐(C#)
- R語(yǔ)言數(shù)據(jù)分析從入門到精通
- Power Up Your PowToon Studio Project
- Banana Pi Cookbook
- Hands-On C++ Game Animation Programming
- JavaCAPS基礎(chǔ)、應(yīng)用與案例
- Unity 2018 Shaders and Effects Cookbook
- C/C++數(shù)據(jù)結(jié)構(gòu)與算法速學(xué)速用大辭典
- 代替VBA!用Python輕松實(shí)現(xiàn)Excel編程
- 深入實(shí)踐Kotlin元編程
- Mastering SciPy
- C語(yǔ)言王者歸來(lái)
- Python編程基礎(chǔ)與數(shù)據(jù)分析
- 深度學(xué)習(xí):基于Python語(yǔ)言和TensorFlow平臺(tái)(視頻講解版)
- SQL Server 2008數(shù)據(jù)庫(kù)應(yīng)用技術(shù)(第2版)