Skip to content

405 Method not allowed error for my delete and patch requests but post and get requests work fine #2417

Answered by davidpdrsn
Benbellah-Owino asked this question in Q&A
Discussion options

You must be logged in to vote

There's gotta be something else wrong because that does work. I just tested this

use axum::{routing::*, Router};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/todo", post(|| async {}).get(|| async {}))
        .route("/todo/:id", delete(|| async {}).patch(|| async {}));

    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();
    axum::serve(listener, app).await.unwrap();
}
❯ curl -i localhost:3000/todo -X GET
HTTP/1.1 200 OK
content-length: 0
date: Mon, 11 Dec 2023 10:28:31 GMT


❯ curl -i localhost:3000/todo -X POST
HTTP/1.1 200 OK
content-length: 0
date: Mon, 11 Dec 2023 10:28:37 GMT


❯ curl -i localhost:300…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Benbellah-Owino
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants