You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're releasing 0.4.0, for which the central focus was supporting multiple format responses in the same endpoint handler (i.e. returning different types). One important use case is returning JSON for `accept: application/json` and HTML for its relevant mime types.
One challenge was: how would the developer experience look like?
In Rails and Ruby it looks like this, very clean, due to lots of magic:
def index
@people = Person.find(:all)
respond_to do |format|
format.html
format.xml { render :xml => @people.to_xml }
end
end
After a few iterations, we've come to shape it into this in Rust:
Taking advantage of axum extractors, we're using Format to say "this is a responder type endpoint" and then using match to immitate Ruby's blocks aesthetics.
Another DX improvement we made is for model validations, all you need is to implement Validatable now:
impl Validatable for super::_entities::users::ActiveModel {
fn validator(&self) -> Box<dyn Validate> {
Box::new(Validator {
name: self.name.as_ref().to_owned(),
email: self.email.as_ref().to_owned(),
})
}
}
// now you can call `user.validate()` freely
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We're releasing 0.4.0, for which the central focus was supporting multiple format responses in the same endpoint handler (i.e. returning different types). One important use case is returning JSON for `accept: application/json` and HTML for its relevant mime types.
One challenge was: how would the developer experience look like?
In Rails and Ruby it looks like this, very clean, due to lots of magic:
After a few iterations, we've come to shape it into this in Rust:
Taking advantage of
axum
extractors, we're usingFormat
to say "this is a responder type endpoint" and then usingmatch
to immitate Ruby's blocks aesthetics.Another DX improvement we made is for model validations, all you need is to implement
Validatable
now:get started: https://loco.rs/docs/getting-started/tour/
repo: https://github.com/loco-rs/loco
0.4.x changelog: CHANGELOG.md
Thanks @haoxins @RobertChang0722 @yinho999 @didy-kpn @clefelhocz2 @PolpOnline @AndreiOrmanji @spencewenski @assapir for participating in this release!
Beta Was this translation helpful? Give feedback.
All reactions