We have serveral services running on an application server and every service has a context. The name of the service is automatically added to the url, since there can be multiple services on the same application server.
Now we are creating a new service, which is called Draws, meaning the url will be
However, now the discussion is the api paths (Resources) to this service. Since we are getting draws, in my mind this should be draws. Which means it will have the url
http://url:port/Draws/draws/{gameNo}
2x draws - Thoughts?
There are thoughts here that the service does only have draws and therefor Draws/{gameNo} is enough.
But in my mind, draws resource is the api interface of the service, like Draws is the book in a library, draws is the chapter... And it should be possible to add more chapters to the book.
Then to implementation, we are using Jersey. That would mean we would have a resource with @Path("{gameNo}").
Edit 1:
There are gateways in front of our services, so the context will never be exposed to end users, it's only there to point to an specific service. Since multiple services can run on the same host:port
Edit 2:
Context part of the url is part of the service discovery lookup
Edit 3:
We are actually not versioning in url, but in Accept header, so actually my url is the same as clementinos but the version part of the url
答案 0 :(得分:1)
我会避免使用2x'draw'。
这是设计URI结构的可能方法。 请注意,这些段应该是小写的(所以不要使用'Draws')
<scheme>://<host>[:<port>]/<api-path>/<api-name>/<api-version>/<resource-path>
答案 1 :(得分:0)
不要在书本,图书馆或章节中弄乱你的思想。只看你的实体:“吸引”你的实体吗?那么它应该是http://url:port/draws/{gameNo}
对于Rest API设计,您可以阅读以下资源:
我建议你看看Richardson成熟度模型。
我也喜欢Github API。 (过去他们曾经建议我们阅读代码来提高我们的才能,现在你也可以阅读其他的API。)
答案 2 :(得分:0)
如果您设计了Draws服务,那么您应该是:
http://url:port/draws/ {gameNo}
如果您计划使用其他端点扩展服务,可能您正在设计更通用的东西。如果是这种情况,请相应地命名。
无论如何,你不应该使用抽奖/抽奖。
另外,我建议使用小写和https(如果可以的话)。
最近,我发布了设计RESTful API时出现的最常见问题的摘要 - How To Design Practical RESTful API,这可能会有所帮助。