Question

I am using Symfony 2 and FOSRestBundle. And when i put this commande :

curl -i -H "Accept: application/json" -H "Content-type: application/json" -X DELETE -d '{"test":{"field":"xxx"}}' http://localhost/tutonew/web/app_dev.php/api/test/4/delete

I Have this Error : HTTP/1.1 405 Method Not Allowed

I'm going to see my source code :

1- First I set my config file :

#app/config/config.yml sensio_framework_extra: view: annotations: false

fos_rest:

param_fetcher_listener: true
body_listener: true
format_listener: true
view:
    view_response_listener: 'force'

2- Under my AdsAPIBundle I just insert the function :

/**
 * @Rest\View(statusCode=204)
 * @Rest\Delete("/api/test/{id}/delete")
 * 
 */
public function deleteTestAction(Request $id) {

    $repo = $this->getDoctrine()->
            getManager()->
            getRepository("MinnAdsAPIBundle:Test");
    $entity = $repo->find($id);
    if (!$entity) {
        throw $this->createNotFoundException('Unable to find test entity!');
    }

    $em = $this->getDoctrine()->getManager();
    $em->remove($entity);
    $em->flush();
}
Was it helpful?

Solution

i solved the problem. I just fix this

public function deleteTestAction(Request $id)

To this :

public function deleteTestAction($id)

And finally i launch this commande

curl -i -X DELETE -d '{"test":{"field":"xxx"}}' http://localhost/tutonew/web/app_dev.php/api/test/4/delete

And i will have this Code :

HTTP/1.1 204 No Content
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top