Crate rocket_post_as_delete

Source
Expand description

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.

§Example

use rocket::{launch, delete, routes};
use rocket_post_as_delete::PostAsDelete;
 
#[launch]
fn rocket() -> _ {
   rocket::build()
       .attach(PostAsDelete)
       .mount("/", routes![delete_foo_bar])
}
 
#[delete("/foo/bar")]
async fn delete_foo_bar() -> String {
    "Poof!".into()
}
 

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.

Structs§