Crates.io | rocket-post-as-delete |
lib.rs | rocket-post-as-delete |
version | 0.1.1 |
source | src |
created_at | 2022-01-08 17:50:27.84264 |
updated_at | 2022-01-08 23:25:32.667112 |
description | A rocket fairing rewriting POST requests with delete suffix to their DELETE counterparts |
homepage | |
repository | https://github.com/misterio77/rocket-post-as-delete |
max_upload_size | |
id | 510364 |
size | 5,852 |
rocket-post-as-delete
is a Fairing for Rocket rewriting
requests such as POST foo/bar/delete
into DELETE foo/bar
.
This is useful when you have web forms (which, unless you use javascript, only
support POST and GET) for deleting stuff, and want to write those routes with
(the more correct) DELETE
verb.
Add to your Cargo.toml
:
rocket-post-as-delete = "0.1"
use rocket_post_as_delete::PostAsDelete;
#[rocket::main]
async fn main() {
rocket::build()
.attach(PostAsDelete)
.mount("/", routes![delete_foo_bar])
.launch()
.await;
}
#[delete("/foo/bar")]
async fn delete_foo_bar() -> String {
"Poof!"
}
Now forms such as this (POST
verb, and submit URL suffixed by /delete
):
<form method="post" action="/foo/bar/delete">
<button>Delete me!</button>
</form>
Will run the delete_foo_bar
route as expected.