New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macros to help using warp #395
Comments
This is pretty cool. I didn’t see any examples of using the macros and passing around application state. Do you have one? |
@carllerche I'm sorry, but I'm not sure what did you mean by Lines 39 to 46 in 2823891
or something like hb in warp/examples/handlebars_template.rs Lines 51 to 54 in 2823891
If you meant the latter, it's implemented as #[filter = "foo_path"]. Anyway, I'm going to add #[data] which allows passing an argument from caller to actual handler. |
I've implemented |
# Macros - [x] `#[router]` improvement - [x] use fn instead of unit struct - [x] #[data] - [x] #[body_size(max = "8192")] - [x] #[cors] - [x] header guard ```rust #[get("/")] #[header("X-Appengine-Cron", "1")] fn gae_cron() -> String { String::new() } ``` - <del> query guard </del>:It's easy to do so with `#[filter]` - [x] `#[cookie = "foo"]` (on an argument) - <del>`#[ws]` (on an argument)</del>: Implemented with `FromRequest` - <del>`#[multipart]` (on an argument)</del>: Implemented with `FromRequest` # Enhancement - [x] Factory pattern We can replace `#[json]`, `#[body]` with automatic detection based on a trait, but it requires nightly **or** dynamic dispatch. ```rust /// One box is created per function which accepts Json<T> #[post("/typed")] pub fn typed(body: Json<LoginForm>) {} /// Everything is statically dispatched #[post("/annotated")] pub fn annotated(#[json] body: LoginForm) {} ``` Related: seanmonstar/warp#395
This is really cool! It sounds similar to what Carl wanted to do with tower-web. I've always wanted warp to provide its FP-style We could add a |
hi @kdy1 , have you seen tower-web? I think what @carllerche meant was something like tower-web's impl_web! macro where you would define a struct to agregate state across handlers, which would then |
I would absolutely love to have the macros in |
I added automatic openapi spec genertion to rweb, and I'm not sure if it would be useful for warp. As macro removes attributes, there's no way to make openapi related code act as 3rd-party library. I mean, openapi annotation should be handled by macros like Anyway, I want to hear more opinion about it. |
I were not aware of it. But rweb supports it via #[data]. You can pass down e.g. db struct to handlers. |
@seanmonstar What's your opinion about openapi spec generator? Do you think it can be feature of warp? If not, I should redesign rweb-macros to be usable with warp. |
I was looking to write something like this! Would be very cool if we could make a The other reason why I am very interested in this is more ergonomic error handling. Concretely, I would like to use |
I took a shot at making my own version of warp-macros based off I did both for fun and for the fact that I didn't want to drag in more dependencies, so it just depends on |
@seanmonstar - Maybe it is worth resurrecting this topic ? This "rweb" library is fantastic. I use warp. But for a long time I had to deal with the fact that it does not support openapi. It was only by accident that I found rweb. Maybe it is worth to give a link in warp documentation to rweb library for a start ? |
I find the OpenAPI generation more valuable than the macro boilerplate generation, but I can see its value, too. These should be seperable! The rweb library isn't able to document correctly if path Filters are used. It's really not able to document unless the macros can tell it what it needs to know, but Filters should be what's telling the OpenAPI spec generator everything. If that were the case, then these concerns would be seperable. I don't think that this is a case where the external library (rweb) can just NewType the relevant filters: this should be something from the Warp Filter trait. |
I wrote macros to ease using warp, and I'm considering merging macros back into warp.
See rweb/tests and rweb/examples to see usage examples.
The text was updated successfully, but these errors were encountered: