Is it bad practice to put a period in a URI path?
I am designing a REST API for a web application. I want to clearly version the API, so that the interface can be changed in the future without breaking existing services. So in my v1开发者_开发问答.0 API, I want to clearly identify it as the v1.0 API, leaving me the freedom to release a future v1.1 version with breaking changes.
My question is, would a period in the path component of a URI be bad practice?
eg. Is there any good reason not to use http://example.com/myapi/v1.0/services as a URI to my service?
Putting a period in the URI is perfectly fine. Putting a version number in an URI is definitely not a best practice.
Here are my reasons why and here is an good article on the subject by someone much smarter than me.
It is perfectly acceptable to use a period in a URI path. It is also valid as per RFC 3986 section 2.3.
its a perfectly valid path character, see page 27 of the spec http://www.ietf.org/rfc/rfc2396.txt
No reason not to use it
I think differently of the others... I don't think it is a good practice to use it on the url.
IMHO it is way better if you version on the Content-Type Header.
As an example, if you are using application/xml:
Content-Type: application/v1.0+xml.
Using the Content-Type, it also indicates that the resource itself is versioned. While if you use it on the url it seems that you are versioning the service (which doesn't seem to be so), and if you are changing the service itself you will probably change the url, so you don't need the version number.
EDIT: You should also use it on the Accept Header, not only on the Content Type.
I think it is a good idea. I've seen several rest services that do this.
精彩评论