views:

24

answers:

1

I am designing a RESTful API for a booking application. There are accommodations that you can request a list or the details. As the application targets a multi-language audience, the descriptions are (sometimes) available in different languages.

Now I'm not sure how to handle these translations in the representation of an accommodation. Without the multiple languages I would make "description" a field or the accommodation object, quite simple.

Any idea how to solve this elegantly?

My current idea: Add a list of descriptions with text<->culture pairs instead of the description field and an additional subressource /descriptions to the accommodation for the creating (POST), updating (PUT) and deleting (DELETE) of new translations.

+2  A: 

For retrieving the representations in the appropriate language you simply set the Accept-Language HTTP header.

Request:

GET /Hotel/345
Accept-Language: fr

Response:

<Hotel>
  <Description xml:lang='fr'>Ce edifice est magnifique</Description>
</Hotel>

For doing the updates you could just include multiple description elements, assuming you are using xml as your media type format.

Request:

PUT /Hotel/345

<Hotel>
  <Description xml:lang='en'>This building is magnificent</Description>
  <Description xml:lang='fr'>Ce edifice est magnifique</Description>
</Hotel>
Darrel Miller
Thanks, that's what I hoped for but there is a requirement to deliver the description in multiple languages, Accept-Language is not an option. Your XML looks good though, shouldn't there be a "<Descriptions>" around the two descriptions?
Jan P.
There does not need to be a "Descriptions" element containing the single Descriptions, that is completely up to you. If you don't want to use the Accept-Language, the GET can return the same document that I used for the PUT. That way you can return as many languages as you like.
Darrel Miller