mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 08:57:00 +02:00
renamed Route::handler to Route::f, added Route::h to register Handler
This commit is contained in:
21
src/route.rs
21
src/route.rs
@@ -227,6 +227,27 @@ impl<S, R, F> RouteHandler<S> for AsyncHandler<S, R, F>
|
||||
}
|
||||
|
||||
|
||||
/// Json response helper
|
||||
///
|
||||
/// The `Json` type allows you to respond with well-formed JSON data: simply return a value of
|
||||
/// type Json<T> where T is the type of a structure to serialize into *JSON*. The
|
||||
/// type `T` must implement the `Serialize` trait from *serde*.
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// # #[macro_use] extern crate serde_derive;
|
||||
/// # use actix_web::*;
|
||||
/// #
|
||||
/// #[derive(Serialize)]
|
||||
/// struct MyObj {
|
||||
/// name: String,
|
||||
/// }
|
||||
///
|
||||
/// fn index(req: HttpRequest) -> Result<Json<MyObj>> {
|
||||
/// Ok(Json(MyObj{name: req.match_info().query("name")?}))
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
pub struct Json<T: Serialize> (pub T);
|
||||
|
||||
impl<T: Serialize> FromRequest for Json<T> {
|
||||
|
Reference in New Issue
Block a user