Hi,
I have a use case in my API to add mandatory parameter(s) on Item Request.
Where's possible to add filter on item Request ?
If not, it's possible to added this feature on version 2.0 ?
Thanks
Bertrand
Hi @Garfield-fr ,
Thanks for using Api-Platform,
Could you please explain more the use case and add an exemple ?
Hi @Simperfit ,
I use 脿 DataProvider to make a request on an external API. To get a record, i have some fields for query:
Url Exemple: http://api/record/{id}?institution=xxx&getDelivery=true
It work with additional parameter on url, but for my api documentation, i don't show this.
I use the new swagger UI, but i don't show Filters.
The attributes parameters to make a filter is on root apiRessource. It's possible ton make this parameter on method ?
Thank's
Bertrand
It's possibles to create filters for item queries directly in the v2.
If you use v1, it's not possible out of the box but a know workaround is to use a custom data provider and to filter in the getItem method.
But what does it mean to have filters when retrieving a single item? I don't think it makes sense...
@dunglas I use the last version 2 (beta 3). I read the documentation but i don't find where's possible to make the filter for Item.
Documentation: @ApiResource(attributes={"filters"={"offer.search"}})
It's posible to make this syntax ?
@ApiResource(
collectionOperations ={"get"={"method"="GET", "attributes"={"filters"={"foo.collection.search"}}},
itemOperations={"get"={"method"="GET", "attributes"={"filters"={"foo.item.search"}}}},
)
And How i use this in my DataProvider ?
Thank's
I was unclear sorry. Filters are only available on collections because it doesn't make sense o on items as pointed out by Teoh.
However a new concept has been introduced in v2 called extensions. Filters themselves are implemented using the extension system and this system is also available for items.
There is no doc for that already (PR are very welcome) but looking at the code should be enough: https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/ItemDataProvider.php
Basically you need to register your extension as a service and mark it with the api_platform.doctrine.orm.query_extension.item tag. Your extension class must implement the QueryItemExtensionInterface interface.
@dunglas Thank's for this explain, but for my use case, i don't use doctrine ORM. My query use Guzzle for External API Service Provider. Is it possible to create an extension without Doctrine ORM ?
My project aggregates multiple external sources without ORM, only with Guzzle.
Thanks
Extensions are only provided for Doctrine ORM. However it's just a way to decouple data providers. You can implement your own extension system for you own data provider easily. Take a look at how it is done for Doctrine.
Hi @dunglas ,
I am using your beautyfull Api Platform and i have a problem with Filter.
how can I get my entities associated in the filters ?
I would like to get such a Person entity and all its Messages in a single request. No links to resources but Message data Message (date, message, object, etc ..)
Thank you and sorry for my English, i am French :)
@foolskill Can you create an issue with what you want to achieve and an exemple of it ?
@foolskill if you would like to embed the relation, read this: https://github.com/api-platform/docs/blob/master/core/serialization-groups-and-relations.md#embedding-relations
You are a solution with normalization_context
I use this and work fine
PS: D茅sol茅 pour mon anglais approximatif ;)
@Simperfit
Thank you but i tried it since this mornig :(
Just look the result. I need your help
thank you and sorry for my english
Including a third level entity (here serviceUnit) works but you also need to add the group (here room) to properties of this entity. Try to add the "room" group to properties of ServiceUnit and they should appear. If it's not the case please paste the code of the ServiceUnit entity.
Thank you i have solve this problem. and i am creating another issues now for another problem about Select Query. :)
Thank you very much
@Garfield-fr Is the question you asked answered ?
@Simperfit yes, it's ok for me.
Thank's
Most helpful comment
@Simperfit yes, it's ok for me.
Thank's