0

First of all I want to implement JSON API. I follow tutorial on api platform and just like in example create entities and response is like

{
    "links": {
        "self": "/api/books"
    },
    "meta": {
        "totalItems": 1,
        "itemsPerPage": 30,
        "currentPage": 1
    },
    "data": [
        {
            "id": "/api/books/1",
            "type": "Book",
            "attributes": {
                "isbn": "9781782164104",
                "title": "Persistence in PHP with the Doctrine ORM",
                "description": "This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM.",
                "author": "Kévin Dunglas",
                "publicationDate": "2013-12-01T00:00:00+01:00",
                "_id": 1
            },
            "relationships": {
                "reviews": {
                    "data": [
                        {
                            "type": "Review",
                            "id": "/api/reviews/1"
                        }
                    ]
                }
            }
        }
    ]
}

My api_platform.yaml config

api_platform:
    mapping:
        paths: ['%kernel.project_dir%/src/Entity']
    formats:
        jsonapi:
            mime_types: ['application/vnd.api+json']

So i have problem with id filed in data. I get id fields in format api/entityName/id but I just want to get number(string), just like in JSON API. So is there some configuration that i miss or is any way to achieve that

2 Answers 2

1

All you need is to send

Accept: application/json

on request header.

Sign up to request clarification or add additional context in comments.

Comments

0

It was discussed here. You need to use Normalizer or create custom getter.

2 Comments

Can you give me some example or some tutorial. Documentation on official site is not very good, especially when is JSON API format. If you are familiar with API-Platform can you look API platform filter
You can create a custom controller for GET action like described in the documentation, then create a custom request to the database and return JSON the response wit id's you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.