I think you should consider using neither http://api.example.com
nor http://example.com/api/v1
.
Instead I would suggest using http://example.com/api
and content negotiation for versioning.
Here are my thoughts why:
Using a subdomain:
Per the URI Scheme Specification, you are defining the API in the authority part of the URI, which is used to define your host, rather than defining an application or API on your host. You are actually creating a different address for your API, which means that authentication might not work for api.example.com as it does for example.com.
A valid reason to do this might be when designing an new instance for mobile devices, e.g. mobile.example.com, but I would consider this more an infrastructural decision and not a functional one.
Using an unversioned path on the main domain:
There are two bits of information here: one is an indication that there is an API resource and the second is that there the version number of that API resource (v1).
There is nothing bad about using /api/
to put a distinction between the API and, for example, your web view that might run under /web/
. This can be considered common best practice.
I am not sure whether you intended this, but your question includes a query on how to solve API versioning. Personally, I think that API versioning should not be done using URLs, as they are intended to stay stable for as long as possible. Cool URIs don't change! Instead, consider using HTTP Content-Type information to version your API. I actually found this method used in VMware documentation. Additionally here is a quite old, but still useful, post about content type versioning by Peter Williams.