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?
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.