how to display total items in json format when building api using api-platform

883 views Asked by At

I am working on an api that is usigin api-platform. I've configured page size. I've seen also thatn in jsonld format is visible the number of total items. I need to get same number but in json format. Is it configurable? If yes, ... how? For completeness, instead of see results in the format:

[
    {
        "id": "42",
        "field": "value"
    },    {
        "id": "42",
        "field": "value"
    }
]
{
    data: [
        {
            "id": "42",
            "field": "value"
        },    {
            "id": "42",
            "field": "value"
        }
    ],
    "totalItems": 42
}
1

There are 1 answers

0
shvv On

I think you need jsonapi format.

API Platform config:

# api/config/packages/api_platform.yaml
api_platform:
    formats:
        jsonld:   ['application/ld+json']
        jsonapi:  ['application/vnd.api+json']
        json:     ['application/json']

or some cheating

# api/config/packages/api_platform.yaml
api_platform:
    formats:
        jsonld:   ['application/ld+json']
        jsonapi:  ['application/json']