REST API: locale
The Internationalization (i18n) feature adds new abilities to the REST API.
To work with API content for a locale, please ensure the locale has been already added to Strapi in the admin panel.
The locale
API parameter can be used to work with documents only for a specified locale. locale
takes a locale code as a value (see full list of available locales).
If the locale
parameter is not defined, it will be set to the default locale. en
is the default locale when a new Strapi project is created, but another locale can be set as the default locale in the admin panel.
For instance, by default, a GET request to /api/restaurants
will return the same response as a request to /api/restaurants?locale=en
.
The following table lists the new possible use cases added by i18n to the REST API and gives syntax examples (you can click on requests to jump to the corresponding section with more details):
- For collection types
- For single types
Use case | Syntax example and link for more information |
---|---|
Get all documents in a specific locale | GET /api/restaurants?locale=fr |
Get a specific locale version for a document | GET /api/restaurants/abcdefghijklmno456?locale=fr |
Create a new document for the default locale | POST /api/restaurants + pass attributes in the request body |
Create a new document for a specific locale | POST /api/restaurants + pass attributes and locale in the request body |
Create a new, or update an existing, locale version for an existing document | PUT /api/restaurants/abcdefghijklmno456?locale=fr + pass attributes in the request body |
Delete a specific locale version of a document | DELETE /api/restaurants/abcdefghijklmno456?locale=fr |
Use case | Syntax example and link for more information |
---|---|
Get a specific locale version for a document | GET /api/homepage?locale=fr |
Create a new, or update an existing, locale version for an existing document | PUT /api/homepage?locale=fr + pass attributes in the request body |
Delete a specific locale version of a document | DELETE /api/homepage?locale=fr |