January 2019
Intermediate to advanced
520 pages
14h 32m
English
Handlers of the Nickel framework take two parameters: a mutable reference to a Request struct and an owned Response instance that we can fill with data. Handlers have to return MiddlewareResult. Every input and output type has a type parameter of a shared data type.
The nickel crate contains the try_with! macro. It needs to unwrap the Result type, but returns an HTTP error if the result equals Err. I created the send_impl method to use the usual ? operator; failure::Error is the error type. I've found this to be more common than using a special macro such as try_with!:
fn send<'mw>(req: &mut Request<Data>, res: Response<'mw, Data>) -> MiddlewareResult<'mw, Data> { try_with!(res, send_impl(req).map_err(|_| StatusCode::BadRequest)); ...Read now
Unlock full access