Best practice regarding REST services and I18N

Use the Accept-Language HTTP header.


I'm not convinced that the language should be part of the "address", the thing that identifies the resource, unless it truly is part of the identity, and the tension you have between

 /actions/{id}

and

 /actions/{lang}/{id}

shows that something is not right.

One alternative approach is to use the HTTP header locale information to pass the language. Another would be to pass the language as a query parameter, it is a modifier of the request.


Couldn't find how to comment but I will go with djna answer. Just wanted to add some:

I'm not a REST expert, but from my point of view, query will be the perfect solution AND supporting HTTP header locale as well.

Example, if HTTP header is sent, use that. If query param lang is sent, override HTTP header.

So you get:

/actions/{id}?lang=es-la

Also, you can specify a default language, not strict to one (but I think it's best to say, English if not specified), but you can get user GEO location to present the info in the clients language, if they don't specify one.

Also accepting the HTTP header goes one step further and giving the client options. It's much easier to configure a HTTP header than to manipulate every request URL with language in the client.

Hope it helps :D

Tags:

Java

Rest

Spring