Actix-web: NormalizePath doesn't work with POST method

Created on 16 Apr 2019  路  6Comments  路  Source: actix/actix-web

Using NormalizePath handler with POST http method won't do anything at all.

I don't think this need a example, but here is my code:

App::with_state(ApiState { database: address })
    .prefix("/api")
    .resource("/contacts/{id}/", |r| {
        r.get().f(contacts::get_single);
    })
    .resource("/contacts/", |r| {
        r.post().with(contacts::post);
        r.get().f(contacts::get);
    })
    .default_resource(|r| {
        // Normalize all paths
        r.h(actix_web::http::NormalizePath::default());
    })

This is clearly a simple API. Sending GET to /api/contacts and /api/contacts/:id will be normalized and return as expect. However, sending POST to /api/contacts to create a new resource will actually fall into contacts::get and get the resources. Sending POST to /api/contacts/ will work as expected.

All 6 comments

because NormalizePath redirects

@fafhrd91 Should we have NormalizePath in 1.0 that modifies URI rather than redirecting?

Maybe, there is ticket for that

@LuciferK9 Nice, I actually just read the docs.rs, where there's nothing stated about POST requests. Maybe it would be a good idea to do so.

@fafhrd91 Would you please refer to this ticket? I didn't find it.

636

Was this page helpful?
0 / 5 - 0 ratings