Search code examples
phprestsymfonyfosrestbundle

FOS REST Bundle: funny thing with a "persons" resource


I'm using FOS Rest bundle to create a REST resource for a "persons" resource, basically the urls are meant to be:

  • List: GET /api/persons
  • Add: POST /api/persons
  • Get single person: GET /api/persons/{id}
  • Modify: PUT /api/persons/{id}
  • Delete: DELETE /api/persons/{id}

So I defined my methods in the controllers as follows:

public function cgetPersonsAction() # List
public function cgetPersonAction(...) # Get single
public function cdeletePersonAction(...) # Delete
#etc...

And here comes the funny part, instead of /api/persons for get single, put, post and delete FOS Rest bundle calculates the plural of person into people instead of persons and the urls ended up being:

  • List: GET /api/persons
  • Add: POST /api/people
  • Get single person: GET /api/people/{id}
  • Modify: PUT /api/people/{id}
  • Delete: DELETE /api/people/{id}

I searched the code looking for maybe some people/person in the bundle but I found nothing, so I guess it must be related with some php plural function.

Do you know if there's any way to force the url to remain being "person"? I think people doesn't make too much sense here


Solution

  • You can force the url by using:

    FOS\RestBundle\Controller\Annotations\Get; ...\Post; ,...
    

    For GET url it would be:

    @Get("api/whatever/{id}")