Is it better to place a REST API on a subdomain or in a subfolder?

Abhijith Prabhakar picture Abhijith Prabhakar · Jan 28, 2013 · Viewed 22.4k times · Source

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.

Should we have the URL pattern http://api.example.com or http://example.com/api/v1?

Is there any standard guidance for this?

Answer

Jobert Enamno picture Jobert Enamno · Jan 28, 2013

It depends on your needs.

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

Last but not least, PayPal uses the pattern http://example.com/api/v1.