actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

Add macro for route handler accepting all HTTP methods

Open tp971 opened this issue 1 year ago • 14 comments
trafficstars

As discussed in https://github.com/actix/actix-web/discussions/3259, implement macros like #[any("...")] and #[route("...", method = any)] to create route handlers accepting all HTTP methods (which is currently only possible with something like app.route("...", web::route().to(handler)))

tp971 avatar Jan 24 '24 18:01 tp971

I will like to take this issue, can you help me figure out the initials and the codebase?

sabinonweb avatar Mar 12 '24 16:03 sabinonweb

Or provide more information

sabinonweb avatar Mar 12 '24 16:03 sabinonweb

You can look inside the actix-web-codegen crate source. I'd recommend adding a trybuild test first using the format mentioned in the OP issue and discussion post.

robjtede avatar Mar 13 '24 17:03 robjtede

When I tried to run trybuild tests using cargo test --test trybuild or even just cargo test, it shows that 0 tests were run. Am i making a mistake? @robjtede

sabinonweb avatar Mar 15 '24 04:03 sabinonweb

Good point. The trybuild tests only run on our MSRV. So Rust 1.72.

robjtede avatar Mar 15 '24 12:03 robjtede

I don't know if it's a dumb question buy may I ask whether the HTTP methods are imported from inbuilt libraries or defined within the source code itself. If they are defined please could you specify where? @robjtede

sabinonweb avatar Mar 15 '24 16:03 sabinonweb

I figured out that it is exported. Now, I will work on defining ALL method kind of thing because an error related to naming conflict was generated

sabinonweb avatar Mar 15 '24 17:03 sabinonweb

Can you guide me on that a little @robjtede ? It's been quite a task

sabinonweb avatar Mar 15 '24 17:03 sabinonweb

@sabinonweb Do you want to open a draft PR so I can see where you've gotten to?

robjtede avatar Mar 15 '24 19:03 robjtede

@robjtede please have a look

sabinonweb avatar Mar 16 '24 11:03 sabinonweb

@robjtede I would love a comment

sabinonweb avatar Mar 16 '24 12:03 sabinonweb

I left some comments earlier. See the PR.

robjtede avatar Mar 16 '24 12:03 robjtede

Would adding methods in with_any_methods, similar to with_methods work @robjtede

sabinonweb avatar Mar 18 '24 15:03 sabinonweb