简体   繁体   English

在Apigility中,如何访问DELETE请求的正文内容

[英]In Apigility, how do I access a DELETE request's body content

I am building an API with Apigility. 我正在使用Apigility构建API。 I am tied to a backend, where deleting a resource requires additional data, not just the resource ID taken from the URL. 我被绑定到一个后端,在那里删除资源需要其他数据,而不仅仅是从URL中获取的资源ID。 So I need to read a parameter fom a DELETE request's body. 因此,我需要从DELETE请求的主体读取参数。

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. 虽然在POST请求的create()方法中,我可以简单地访问$ data参数,但这不适用于DELETE方法,因为仅提供了$id

Accessing $this->getEvent()->getRequest(); 访问$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. 在我的资源类的delete()方法中,我看到请求的主体内容(表单数据)包装成一个名为“ content”的属性-作为字符串。

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. Apigility不会将任何数据传递给DELETE请求,因此不会将其传递给事件参数。 You can just retrieve it from the request as you discovered and do the json_decode yourself. 您可以从发现的请求中检索它,然后自己进行json_decode。

public function delete($id)
{
    $body = $this->getEvent()->getRequest()->getContent();
    $data = json_decode($body, true);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM