删除一堆项目的宁静方式 [英] Restful way for deleting a bunch of items

查看:46
本文介绍了删除一堆项目的宁静方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于 REST 的维基文章表示如果您使用 http://example.com/resources DELETE,则表示您正在删除整个收藏.

In wiki article for REST it is indicated that if you use http://example.com/resources DELETE, that means you are deleting the entire collection.

如果您使用 http://example.com/resources/7HOU57Y DELETE,则表示您是删除那个元素.

If you use http://example.com/resources/7HOU57Y DELETE, that means you are deleting that element.

我正在做一个网站,注意不是网络服务.

I am doing a WEBSITE, note NOT WEB SERVICE.

我有一个列表,列表中的每个项目都有 1 个复选框.一旦我选择了多个要删除的项目,我将允许用户按下一个名为 DELETE SELECTION 的按钮.如果用户按下按钮,将弹出一个 js 对话框,要求用户确认删除.如果用户确认,则删除所有项目.

I have a list that has 1 checkbox for each item on the list. Once i select multiple items for deletion, i will allow users to press a button called DELETE SELECTION. If user presses the button, a js dialog box will popup asking user to confirm the deletion. if user confirms, all the items are deleted.

那么我应该如何以 RESTFUL 的方式删除多个项目?

So how should i cater for deleting multiple items in a RESTFUL way?

注意,目前用于网页中的 DELETE,我所做的是使用带有 POST 的 FORM 标记作为操作,但包含一个值为 DELETE 的 _method,因为 这是其他人在 SO 中指出的如何对网页进行 RESTful 删除.

NOTE, currently for DELETE in a webpage, what i do is i use FORM tag with POST as action but include a _method with the value DELETE since this is what was indicated by others in SO on how to do RESTful delete for webpage.

推荐答案

我认为 rojoca 的答案 是迄今为止最好的.一个细微的变化可能是,取消同一页面上的 javascript 确认,而是创建选择并重定向到它,在该页面上显示一条确认消息.换句话说:

I think rojoca's answer is the best so far. A slight variation might be, to do away with the javascript confirm on the same page, and instead, create the selection and redirect to it, showing a confirm message on that page. In other words:

来自:http://example.com/resources/

做一个

带有选择的 ID 的 POST 到:
http://example.com/resources/selections

POST with a selection of the ID's to:
http://example.com/resources/selections

如果成功,应该回复:

HTTP/1.1 201 创建,位置标头到:
http://example.com/resources/selections/DF4XY7

HTTP/1.1 201 created, and a Location header to:
http://example.com/resources/selections/DF4XY7

在此页面上,您将看到一个 (javascript) 确认框,如果您确认将执行以下请求:

On this page you will then see a (javascript) confirm box, which if you confirm will do a request of:

删除http://example.com/resources/selections/DF4XY7

如果成功,应该回复:HTTP/1.1 200 Ok(或任何适合成功删除的内容)

which, if successful, should respond with: HTTP/1.1 200 Ok (or whatever is appropriate for a successful delete)

这篇关于删除一堆项目的宁静方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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