I am building an API with Apigility. I am tied to a backend, where deleting a resource requires additional data, not just the resource ID taken from the URL. So I need to read a parameter fom a DELETE request's body.
While in POST request's create()
method I can simply access the $data parameter, this does not work with DELETE methods, because only $id
is provided.
Accessing $this->getEvent()->getRequest();
in my Resource classes' delete()
method, I see the request's body content (form-data) wrapped into a property called 'content' - as a string.
Can someone point me at what I am missing to access the body's key-value pairs?
Apigility does not expect any data to be passed to a DELETE
request, so it does not pass it to the event params. You can just retrieve it from the request as you discovered and do the json_decode yourself.
public function delete($id)
{
$body = $this->getEvent()->getRequest()->getContent();
$data = json_decode($body, true);
}