Marc
Marc boosted

Dear #Rust#RustLang folks doing #Axum

What's your preferred way of having a single handler for multiple form submission types?

That is, let's say I have a settings page, and there's different "sections" to the settings, which all get handled differently, but I want the Form to get deserialized per usual?

Unfortunately, serde_html_form doesn't support deserializing enums for something like this? At least not out of the box?

Dear #Rust#RustLang folks doing #Axum

What's your preferred way of having a single handler for multiple form submission types?

That is, let's say I have a settings page, and there's different "sections" to the settings, which all get handled differently, but I want the Form to get deserialized per usual?

Unfortunately, serde_html_form doesn't support deserializing enums for something like this? At least not out of the box?

Excellent. Got this working in the #ConjuredInk#Rust#RustLang #Axum server.

If you just wrap any plain

with , it鈥檒l submit that form as a fetch instead. Server-side, a middleware checks for a header and sets a flag, and you can use that to only partially render the response.

Without JS, you get the some whole page back, just like normal. With working JS, you only get the "patch", and then overwrites the matching nodes.

This is a hybrid of htmx and htmz that uses a web component instead of a global thing with odd attribute annotations, and unlike htmz, lets you have programmatic lifecycle hooks, set that header so you can share the exact same endpoint, etc.

And it鈥檚 still just a tiny, plain, standalone Web Component with no deps. It's a couple of kb mingz, and I'll probably golf it around a bit to make it smaller.

#WebDev

Dear #rust#RustLang folks who use #axum

Do you have a nice router crate you recommend? My use case here is that I have a lot of situations where I want to actually resolve routes (to generate links and the like) and I really dislike how untyped/unverified those random strings are.

https://crates.io/crates/axum-routes seems good, but it's somewhat low usage. Still, it's pretty small and seems to do exactly what I need (lets me keep separating route definition from handler definition, lets me do reverse lookups, does static route typing, etc)

@zkat axum_extra::routing (https://docs.rs/axum-extra/latest/axum_extra/routing/) adds a typed layer and lives in the regular #axum repo.

Haven't used it for anything huge yet, but it should handle your bullet points and I'm happy enough with it in Tyck. (https://codeberg.org/natkr/tyck)

Dear #rust#RustLang folks who use #axum

Do you have a nice router crate you recommend? My use case here is that I have a lot of situations where I want to actually resolve routes (to generate links and the like) and I really dislike how untyped/unverified those random strings are.

https://crates.io/crates/axum-routes seems good, but it's somewhat low usage. Still, it's pretty small and seems to do exactly what I need (lets me keep separating route definition from handler definition, lets me do reverse lookups, does static route typing, etc)

I did a RIIR again and:

Two apps nearly-identical in functionality now. On startup, before processing anything:

#Rust + #Axum: 3.5MB RES
#Elixir + #Phoenix: 75MB RES

Literally 20x difference, and I haven't even benchmarked throughput/perf. For a use case where a big goal is extremely low resource use, this is huge.

(both of these are running in release/prod mode btw)

I did a RIIR again and:

Two apps nearly-identical in functionality now. On startup, before processing anything:

#Rust + #Axum: 3.5MB RES
#Elixir + #Phoenix: 75MB RES

Literally 20x difference, and I haven't even benchmarked throughput/perf. For a use case where a big goal is extremely low resource use, this is huge.

(both of these are running in release/prod mode btw)

Hey rustaceans, I need to plug my #axum server which uses the tracing crate for logs to our elasticsearch logging service, which uses ESC I believe?
It seems there's no off the shelf tracing_layer to talk to elasticsearch , and trying to write my own I'm running in the issue of needing to use an async method to send the message from a sync context (on_event() of tracing::Layer). Anything I've missed to make my live easier? #rustlang #tokio #elasticsearch