0
votes

I have an Api-Platform project where I have a rest-api that shows certain data. Currently the api returns ALL information, which isn't good. Can someone push me in the right direction?

I found this for adding extra data: https://api-platform.com/docs/core/serialization/#decorating-a-serializer-and-add-extra-data

Should I use the decorator approach mentioned in the doc above and just unset the fields that I don't want displayed? Is there perhaps some annotation I could use above fields in the entities so that they are omitted?

Thanks.

1

1 Answers

0
votes

So I found a simple solution if you are using annotations:

The "@Groups()" above each field in an entity decides whether or not the data for the given field is readable.

Before I had this annotated above each field "* @Groups({"READ"})", removing it will not display the fields data when calling the api.

More info here: https://api-platform.com/docs/core/serialization/#the-serialization-context-groups-and-relations