Strapi is an open-source headless CMS that gives developers the freedom to choose their favorite tools and frameworks and allows editors to manage and distribute their content using their application’s admin panel.
API parameters can be used in conjunction with the REST API to filter, sort, and page results, as well as select fields and relationships to populate.In addition, you can use specific parameters related to optional Strapi features, such as publication status and locale Settings for content types
Operator | Type | Description |
sort | String or Array | Sort the response |
filters | Object | Filter the response |
populate | String or Object | Populate relations, components, or dynamic zones |
fields | Array | Select only specific fields to display |
pagination | Object | Page through entries |
publicationState | String | Select the Draft & Publish state Only accepts the following values: 1. live |
locale | String or Array | Select one or multiple locales |
Fields
Queries can accept a fields parameter to select only some fields.
GET /api/users?fields[0]=title&fields[1]=body {
"data": [
{
"id": 1,
"attributes": {
"title": "test1",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
}
}
],
"meta": {
// ...
}
} Population
Queries can accept a populate parameter to populate various field types:
- relations & media fields
- components & dynamic zones
- creator fields
GET /api/articles?populate=* {
"data": [
{
"id": 1,
"attributes": {
"title": "Test Article",
"slug": "test-article",
"body": "Test 1",
// ...
"headerImage": {
"data": {
"id": 1,
"attributes": {
"name": "17520.jpg",
"alternativeText": "17520.jpg",
"formats": {
// ...
}
// ...
}
}
},
"author": {
// ...
},
"categories": {
// ...
}
}
}
],
"meta": {
// ...
}
} GET /api/articles?populate[0]=categories {
"data": [
{
"id": 1,
"attributes": {
"title": "Test Article",
// ...
"categories": {
"data": [
{
"id": 1,
"attributes": {
"name": "Food"
// ...
}
}
]
}
}
}
],
"meta": {
// ...
}
} Filtering
The following operators are available:
Operator | Description |
$eq | Equal |
$eqi | Equal (case-insensitive) |
$ne | Not equal |
$lt | Less than |
$lte | Less than or equal to |
$gt | Greater than |
$gte | Greater than or equal to |
$in | Included in an array |
$notIn | Not included in an array |
$contains | Contains |
$notContains | Does not contain |
$containsi | Contains (case-insensitive) |
$notContainsi | Does not contain (case-insensitive) |
$null | Is null |
$notNull | Is not null |
$between | Is between |
$startsWith | Starts with |
$startsWithi | Starts with (case-insensitive) |
$endsWith | Ends with |
$endsWithi | Ends with (case-insensitive) |
$or | Joins the filters in an "or" expression |
$and | Joins the filters in an "and" expression |
$not | Joins the filters in an "not" expression |
GET /api/users?filters[username][$eq]=John [
{
"id": 1,
"username": "John",
"email": "john@test.com",
"provider": "local",
"confirmed": true,
"blocked": false,
"createdAt": "2021-12-03T20:08:17.740Z",
"updatedAt": "2021-12-03T20:08:17.740Z"
}
] Sorting
Queries can accept a sort parameter that allows sorting on one or multiple fields.
GET /api/articles?sort[0]=title&sort[1]=slug {
"data": [
{
"id": 1,
"attributes": {
"title": "Test Article",
"slug": "test-article",
// ...
}
},
{
"id": 2,
"attributes": {
"title": "Test Article",
"slug": "test-article-1",
// ...
}
}
],
"meta": {
// ...
}
} Pagination
To paginate results by page, use the following parameters:
Parameter | Type | Description | Default |
pagination[page] | Integer | Page number | 1 |
pagination[pageSize] | Integer | Page size | 25 |
pagination[withCount] | Boolean | Adds the total numbers of entries and the number of pages to the response | True |
GET /api/articles?pagination[page]=1&pagination[pageSize]=10 {
"data": [
// ...
],
"meta": {
"pagination": {
"page": 1,
"pageSize": 10,
"pageCount": 5,
"total": 48
}
}
} There are just some simply usages of Strapi. You can find more detailed documentation here.
0 Comments