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.
because NormalizePath redirects
Documented here: https://actix.rs/docs/url-dispatch/
@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.