将REST API放在子域或子文件夹中更好吗? [英] Is it better to place a REST API on a subdomain or in a subfolder?
问题描述
我们有一个Web应用程序,其中包含URL http://example.com
。现在我们想要扩展这个应用程序的一部分作为一个宁静的服务,我们正在讨论最好的URL模式。我搜索过,但找不到任何具体的指导。
We have a web application which is hosted with the URL http://example.com
. 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.
我们是否应该使用网址格式 http://api.example.com
或 http://exaple.com/api/v1
?
Should we have the URL pattern http://api.example.com
or http://exaple.com/api/v1
?
这是否有任何标准指导?
Is there any standard guidance for this?
推荐答案
取决于根据您的需求。
如果您使用 http://api.example .com 它使您的API成为子域名。基本上,如果您的REST服务要由多个客户端使用,则此URL模式很好,但如果只有一个客户端连接到您的API,那么模式 http://example.com/api/v1 很好。但是,如果您想添加更多API并连接更多客户端,则最好使用 http://示例。 COM / API / V1 。例如,请考虑以下事项。
If you use http://api.example.com 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 http://example.com/api/v1 is good. However, if you want to add more API with more clients connected to it it’s better to use http://example.com/api/v1. For example, consider the following.
http://example.com/reportapi/apioperation?parameters
http://example.com/paymentapi/apioperation?parameters
http://example.com/searchapi/apioperation?parameters
最后但并非最不重要的是,PayPal使用的模式是 http:/ /example.com/api/v1 。
Last but not least, PayPal uses the pattern http://example.com/api/v1.
这篇关于将REST API放在子域或子文件夹中更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!