web api - Supporting multiple languages in a REST API -
i have collection of cities i'm creating rest api (my first rest api). each city has number of language independent things, such founding date , population count. cities have things depend on language, such title , short description. internally city documents have format:
{ "population": 9042, "name": { "en": "berlin", "nl": "berlijn", // ... }, // ... }
the users of api want view city info specific language only, , like:
{ "population": 9042, "name": berlin, // ... }
i've made these accessible via /cities/:id/:language_code
, instance cities/123/en
. want implement listing of cities: get /cities
. there requested language needed. since result in /cities/:language_code
, i'm getting impression putting @ end of url not idea, , suspect i'll better off /en/cities/...whatever...
.
how typically done in rest apis? big, nicely implemented, api out there example?
rest api's based upon http protocol, can use headers, traditionaly used defined prefered locale.
so use accept-language
parameter this.
# request /cities/.... http/1.1 host: www.example.org accept-language: en,en-us,fr;q=0.6
would give :
{ "population": 9042, "name": berlin, // ... }
Comments
Post a Comment