RESTful - DELETE响应主体应包含什么 [英] RESTful - What should a DELETE response body contain

查看:596
本文介绍了RESTful - DELETE响应主体应包含什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个API可以让用户获得:

Let's say I have an API where you can get users:

GET /RESTAPI/user/

您可以按以下方式删除用户:

And you can delete users by:

DELETE /RESTAPI/user/123

什么是 RESTful约定关于DELETE的响应主体应该包含什么?
我预计它应该是所有用户的新列表,现在不再包含id为123的用户。

What is the RESTful convention on what the DELETE's response body should contain? I expected it should be the new list of all users which now doesn't contain the user with id 123 anymore.

谷歌搜索没有得到我任何令人满意的答案。我只发现了如何做到这一点的意见,但是没有RESTful服务的严格定义

Googling around didn't get me any satisfying answers. I only found opinions on how to do that, but isn't there a strict definition of RESTful Services?

这不是重复的 RESTful API POST / DELETE应该返回什么身体?什么是REST PUT / POST / DELETE调用应按约定返回?
因为此问题要求对DELETE进行严格定义。这些问题只能通过松散的意见来回答。

This is NOT a duplicate of What should a RESTful API POST/DELETE return in the body? and What REST PUT/POST/DELETE calls should return by a convention? since this questions asks for a strict definition regarding DELETE. Those questions were only answered by loose opinions only.

推荐答案

你没有得到硬答案的原因是因为没有硬的RESTful标准。因此,我只能建议您创建一个硬标准并在自己的API中坚持使用

The reason you get no hard answers is because there is no hard RESTful standard. So I can only suggest that you create a hard standard and stick to it within your own APIs

我将此作为RESTful服务的指南 http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful- api

I used this as a guide for RESTful services http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

它表示回复204状态和空身

It says respond with a 204 status and an empty body

我坚持那些标准并将其记录在任何想要使用我的API的人身上

I stick to those standards and document them well for anyone who wants to use my APIs

这篇关于RESTful - DELETE响应主体应包含什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆