For example if I have a function annotated with
and another
Only the first one registered as a service will resolve and the other returns 404.
This is when adding the routes to a ServiceConfig ie
cfg.service(handler::delete).service(handler::get)
I tried to work around this using the guard option from codegen but apparently it doesn't try the next matching request if the guard fails because the result is the same.
Since attributes are parsed independently they are not really aware of each other.
Since path attribute overwrite code and remove next attribute, it is not going to be parsed(otherwise it would cause error)
The fix would require for attribute to parse all other attributes that follow it.
I see how that might be complicated but from a usability standpoint I don't think this can be ignored. If your working on a RESTful API then you are going to have a resource that has different handlers for each HTTP method.
Just to make sure we have maximum understanding I'm going to give a more realistic example of two handlers.
#[get("/thething")]
fn get_thing(req: HttpRequest) -> HttpResponse {
// Retrieves a thing
}
#[post("/thething")]
fn create_thing(req: HttpRequest) -> HttpResponse {
// Creates a thing
}
// Meanwhile in the App configuration
.service(create_thing).service(get_thing)
// Today only one of those routes works.
Yes, this is clear. It is a bug. I鈥檒l fix it later
@glademiller i can not reproduce this problem.
https://github.com/actix/actix-web/blob/master/actix-web-codegen/tests/test_macro.rs#L33
please provide PR with test case if you still see the problem
Now that I look back I'm pretty sure I was using a manually defined resource as the post or put and the get using codegen. In those cases I can't really use the codegen until I can provide a global JSON Config.
Most helpful comment
Yes, this is clear. It is a bug. I鈥檒l fix it later