简体   繁体   English

如何在 HTTP DELETE 请求中传递额外的参数?

[英]How to pass extra parameters in HTTP DELETE request?

I am writing a REST API, which supports POST/GET/DELETE method for the same url.我正在编写一个 REST API,它支持相同 url 的 POST/GET/DELETE 方法。

For the DELETE method, the API needs extra parameters (details of the deletion).对于 DELETE 方法,API 需要额外的参数(删除的详细信息)。 But the library I am using doesn't support request body for DELETE method, how can I do it?但是我使用的库不支持 DELETE 方法的请求正文,我该怎么做?

If I put the parameter in URL like:如果我将参数放在 URL 中,例如:

DELETE /API/Resource/id/parameter

Then I break the RESTyness.然后我打破了RESTyness。 Or I need to use another method POST/PUT, which is not RESTy, either.或者我需要使用另一种方法 POST/PUT,它也不是 RESTy。

Why is POST / PUT not RESTy?为什么 POST / PUT 不是 RESTy? Take a look at the twitter REST API : You can destroy a status by POSTing to /statuses/id/destroy .看看twitter REST API :您可以通过 POST 到/statuses/id/destroy That request does accept parameters.该请求确实接受参数。 You could do something similar to this:你可以做类似的事情:

POST /API/Resource/id/destroy

I think that is RESTy enough.我认为这已经足够了。

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

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