Custom Collection "GET" Method - API Platform
See original GitHub issueHi everyone,
I have an entity that i can get with the standard get operation (collection / or id one) :
/**
* Insee
*
* @ApiResource(
* collectionOperations={"get"},
* itemOperations={"get"},
* attributes={
* }
* )
* @ApiFilter(SearchFilter::class, properties={"insCode": "exact", "insLibelle": "partial"})
* @ORM\Table(name="dif_zonages.insee", indexes={@ORM\Index(name="FK_INSEE_CANTON", columns={"CAN_CODE"})})
* @ORM\Entity
*/
class Insee
{
/**
* @var string
*
* @ORM\Column(name="INS_CODE", type="string", length=5, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $insCode = '';
/**
* @var string|null
*
* @ORM\Column(name="INS_LIBELLE", type="string", length=254, nullable=true)
*/
private $insLibelle;
/**
* @var float|null
*
* @ORM\Column(name="INS_LATITUDE", type="float", precision=10, scale=0, nullable=true, options={"comment"="Latitude de la commune (coordonnées géographiques)"})
*/
private $insLatitude;
/**
* @var float|null
*
* @ORM\Column(name="INS_LONGITUDE", type="float", precision=10, scale=0, nullable=true, options={"comment"="Longitude de la commune (coordonnées géographiques)"})
*/
private $insLongitude;
/**
* Constructor
*/
public function __construct()
{
$this->insdCodeSource = new \Doctrine\Common\Collections\ArrayCollection();
}
Etc .....
/**
* @return float|null
*/
public function getInsLatitude(): ?float
{
return $this->insLatitude;
}
/**
* @param float|null $insLatitude
*/
public function setInsLatitude(?float $insLatitude): void
{
$this->insLatitude = $insLatitude;
}
/**
* @return float|null
*/
public function getInsLongitude(): ?float
{
return $this->insLongitude;
}
/**
* @param float|null $insLongitude
*/
public function setInsLongitude(?float $insLongitude): void
{
$this->insLongitude = $insLongitude;
}
}
However, i want to add a custom "GET"opération so i can get a list of Insee object from 2 parameters : latitude and longitude. Can you help me what should i use? I saw that we can create Extension but the doc is very limited so…
Thanks in advance !
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
API Platform - How to create a custom collection operation ...
I'm using Symfony 5 and Doctrine, I exposed entities with annotation @Api Platform and I see CRUD operations on the API doc. But...
Read more >Creating Custom Operations and Controllers - API Platform
This custom operation behaves exactly like the built-in operation: it returns a JSON-LD document corresponding to the id passed in the URL.
Read more >Custom Resource GET Item > API Platform Part 3
Our collection operation returns some hardcoded DailyStats . Let's pretend that we have a JSON file filled with this data... or maybe in...
Read more >How to use custom DTO's in API Platform? ⋆ Developer Wouter
API Platform then creates the basic CRUD (create, read, update, delete) endpoints, such as GET, POST, PUT and DELETE. This is fine for...
Read more >Healthcheck - Custom Endpoint [API Platform]
Hard To Port. With the DB reset process disabled for the time being, let's see where we now get with our test: vendor/bin/behat ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Would be nice to add an example of this in the documentation. Something that shows how a minimal implementation would loook like.
What this action should return (we know that on item_operation GET we can return either an entity or a
Response, what should we return for a collection GET? A Doctrine collection? Anarray|\Traversable?@foxsdev Any usefull example? I’have already try by tagging DataProvider (custom-collection-data-provider) but it’s doesn’t work as expected