我们有一个Web应用程序,其中包含URL example 。现在我们想要扩展这个应用程序的一部分作为一个宁静的服务,我们正在讨论最好的URL模式。我搜索过,但找不到任何具体的指导。
We have a web application which is hosted with the URL example. Now we want to extend a part of this application as a restful service, and we are debating on the best URL pattern. I searched, but could not find any concrete guidance.
我们是否应该使用网址格式 api.example 或 exaple/api/v1 ?
Should we have the URL pattern api.example or exaple/api/v1?
这是否有任何标准指导?
Is there any standard guidance for this?
推荐答案取决于根据您的需求。
如果您使用 http://api.example 它使您的API成为子域名。基本上,如果您的REST服务要由多个客户端使用,则此URL模式很好,但如果只有一个客户端连接到您的API,那么模式 example/api/v1 很好。但是,如果您想添加更多API并连接更多客户端,则最好使用 http://示例。 COM / API / V1 。例如,请考虑以下事项。
If you use api.example it makes your API a subdomain. Basically, this URL pattern is good if your REST service is to be consumed by multiple clients, but if only one client is connected to your API then the pattern example/api/v1 is good. However, if you want to add more API with more clients connected to it it’s better to use example/api/v1. For example, consider the following.
example/reportapi/apioperation?parameters example/paymentapi/apioperation?parameters example/searchapi/apioperation?parameters最后但并非最不重要的是,PayPal使用的模式是 http:/ /example/api/v1 。
Last but not least, PayPal uses the pattern example/api/v1.
更多推荐
将REST API放在子域或子文件夹中更好吗?
发布评论