Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice regarding REST services and I18N

Tags:

java

rest

spring

I have a client app that communicates with a server using REST services. The client app is multilingual which means the server must be aware of the user's locale during calls. I want to use the "post for location" approach as that has a nice and restful feel to it. When data gets posted to say the actions resource then the uri is:

/actions/{language}

The language is important so that I can localize error messages (or sometimes the returning data) for a GET. Now when the server responds it needs to send back the URI of the resource. If I send back

/actions/{id}

where id is the id of the newly created resource, this isn't entirely correct as

/actions/{language}/{id}

would be the URI of the localized resource. However the actual resource is without the language context.

Any opinions on best practice for this scenario?

like image 251
P Hemans Avatar asked Jul 01 '11 05:07

P Hemans


2 Answers

Use the Accept-Language HTTP header.

like image 200
kalithlev Avatar answered Oct 03 '22 03:10

kalithlev


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.

like image 34
djna Avatar answered Oct 03 '22 04:10

djna