Reputation: 450
Is there a REST best practice for GETting resources in different languages. Currently, we have
www.mysite.com/books?locale=en
I know we can use the accept-language header but is it better for us to do
www.mysite.com/books/en or www.mysite.com/books.en
or does it not matter?
Upvotes: 7
Views: 5600
Reputation: 28435
I am agree with comment of manuel-aldana in the answer to the question RESTful URL: where should I put locale? example.com/en/page vs example.com/page?locale=en
Check for parameter (e.g. locale=en ) first to allow client explicitely specify language with fallback to Accept-Language
Upvotes: 0
Reputation: 16951
I think best way would be to implement this following way:
In other words you can accept language from both sources. Implementation will be following:
With this approach you can make sure that a) path routing will be language agnostic and your system will work uniformly with paths; b) language handling/negotiation will be completely separated from your scripts. You can use language information in your scripts without even knowing what was the source and how it was requested.
Upvotes: 7
Reputation: 19295
If you're trying to have your server return different translations or localized versions of the same books (in other words, the same resource from a RESTful perspective), then use Accept-Language because the resource is the same but the representation is different based on the client's needs.
However if you're trying to return completely different books based on the client's locale (say, returning books written in French if you know that the user is in France) then the URIs should be different since different resources would be returned. At this point, you're talking more about a query request more than anything else. For what it's worth, the /books/en
approach sounds reasonable. Another approach would be to add the locale or language as a resource parameter to GET as /books?lang=en
.
Upvotes: 21