Reputation: 42758
I've just began building a multilingual REST API and are unsure on if there's any convention to follow regarding how I should integrate the multilinguality properly.
Below is a list of alternatives I have come up with, not knowing which makes most sense.
Option 1:
Language-variable in URI: http://myapi.com/en/users/john
Option 2:
Returning only error codes for translation client side:
GET http://myapi.com/users/john => HTTP 404 {status: false, error_code: "321"}
Option 3:
Returning in all available languages: GET http://myapi.com/users/john => {status: false, error_en: "User not found", error_sv: "Anvandaren finns inte"}
Upvotes: 5
Views: 2926
Reputation:
For content negotiation as for negotiating the natural language of a representation, HTTP provides the request header Accept-Language
:
Accept-Language: da, en-gb;q=0.8, en;q=0.7
If possible, the server replies to this request with a response header Content-Language
:
Content-Language: da
Only if the resources are different resources for different languages, the language should be part of the URI. If not, content negotiation should be used.
Upvotes: 10