[SOLVED] Does Vapor support DELETE from HTML Form?

Issue

To delete a user through an admin panel i want to fire a delete request from an HTML Form. Does Swift Vapor support put/patch/delete through hidden html input similar to e.g. Laravel? If not what would the proper way to delete something be?

<!-- Laravel example -->
<input type="hidden" name="_method" value="DELETE">

https://laravel.com/docs/7.x/routing#form-method-spoofing

Solution

For anyone wrapping his/her head around the same thing. As the comments already say, i decided to go the way of using a post request. I registered my routes as follows:

func boot(routes: RoutesBuilder) throws {
    let user = routes.grouped("user")
    user.get(use: getAll)
    user.get(":userid", use: getOne)
    user.post(use: create)
    user.post(":userid","delete", use: delete)
}

Answered By – Deitsch

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.