Open jpkleemans opened 8 years ago
I don't think this is the idea. You are returning a link to the actual resource so just books.
This way you get the correct link of /books/{book_ID}
I think this fine to do. I've seen many APIs that do this. It's situational of course but you should be able to do this.
I ended up created a propietaryJsonApiSerializer, that does two things:
It allows me to set the resource key in the transformer, simply because having to add in the resource key for every single item/collection call seems really shitty.
I added a check for the data array. If it includes _resourceAddress, then I use that instead of the auto generated $resourceKey/$id links.
https://gist.github.com/seant23/2e049f73b3cf9b52635a3cd0b9fc9c50
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 4 weeks if no further activity occurs. Thank you for your contributions.
Lets say I have the following endpoint:
/authors/{author_id}/books/{book_id}
. How can I create the output for this endpoint with Fractal, and keeping the correct links?I was thinking about something like:
But this outputs
/authors.books/{book_id}
as self-link. Which makes sense when you see https://github.com/thephpleague/fractal/blob/master/src/Serializer/JsonApiSerializer.php#L77