How to organize my multilingual REST API?

I just started creating a multilingual REST API and am not sure if there is any agreement on how to integrate multilingualism correctly.

Below is a list of alternatives that I came up with, not knowing what makes sense.

Option 1:
URI language variable: http://myapi.com/en/users/john

Option 2:
Returning only error codes for the translation side: GET http://myapi.com/users/john => HTTP 404 {status: false, error_code: "321"}

Option 3:
Returns in all available languages: GET http://myapi.com/users/john => {status: false, error_en: "User not found", error_sv: "Anvandaren finns inte"}

+4
source share
1 answer

For content negotiation , because HTTP provides the Accept-Language request header to negotiate the natural presentation language:

 Accept-Language: da, en-gb;q=0.8, en;q=0.7 

If possible, the server responds to this request using the Content-Language response header :

 Content-Language: da 

Only if the resources are different resources for different languages ​​should the language be part of the URI. If not, use content negotiation.

+8
source

Source: https://habr.com/ru/post/1444327/


All Articles