REST and localized resources

I want my resources to be localized in several languages. How should multiple languages ​​be sent to a resource using the REST architecture?

resource: / chapters, / chapters /: id

When POST is issued in chapters, the client send data structure:

{localizations: { en: {title: 'New chapter' },sk: {title: 'Nova kapitola'} }}

and a new chapter is created with the localizations of en and sk.

When a client wants to access this chapter at URL / chapter / 1, only one language mutation should be returned in the view. How should I have a domain of language definition? I can use the Accept-Language HTTP header with the desired locale, Accept-Language: sk, or I can include the locale in the url like / chapters / 1 / en.

Also, how to handle a PUT request? In most cases, only one language mutation is updated, but occasionally 2 or more of them will be updated.

+4
source share
1 answer

To update the data, the language must be specified in the data payload, as you described. This works great.

For selection, it depends on whether you want to allow 1) binding and 2) clients to change their chosen language. I would say that you want both to be much easier and more preferable to change the URL or switch the language in your application, and then go into the browser and change the locale settings in the browser.

So, check your url, application cookies or user application data for the language and use the Accept-Language headers as a backup.

I do not understand your PUT request request. The data structure you describe will handle multiple language updates just fine, no? You can handle PUT pretty much as you want, as long as the URL, which is PUT, remains an addressable resource.

+1
source

All Articles