Json response middleware for iron
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Merge branch 'master' of github.com:sunng87/iron-json-response May 10, 2017
src Add JsonResponseMiddleware::new() Mar 23, 2017
.gitignore
.travis.yml (fix) update travis config Mar 8, 2017
Cargo.toml (cargo-release) start next development iteration 0.6.1-alpha.0 Nov 28, 2017
README.md Add JsonResponseMiddleware::new() Mar 23, 2017

README.md

Iron Json Response

Build Status

Middleware for json or jsonp response with Iron framework. Using serde for data type and serialization.

Usage

Setup

Middleware setup:

extern crate iron_json_response as ijr;
use ijr::{JsonResponseMiddleware, JsonResponse};

let mut chain = Chain::new(...);
chain.link_after(JsonResponseMiddleware::new());
...

Json

Send json data:

fn handler(req: &mut Request) -> IronResult<Response> {
    let mut resp = Response::new();
    let data = ...

    resp.set_mut(JsonResponse::json(data)).set_mut(status::Ok);
    Ok(resp)
}

Jsonp

Send json data via jsonp:

fn handler(req: &mut Request) -> IronResult<Response> {
    let mut resp = Response::new();
    let data = ...

    resp.set_mut(JsonResponse::jsonp(data, "cb".to_owned())).set_mut(status::Ok);
    Ok(resp)
}

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.