https://github.com/sunng87/iron-json-response
Json response middleware for iron
https://github.com/sunng87/iron-json-response
iron rust webframework
Last synced: 5 months ago
JSON representation
Json response middleware for iron
- Host: GitHub
- URL: https://github.com/sunng87/iron-json-response
- Owner: sunng87
- Created: 2016-04-04T03:25:39.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-28T10:29:20.000Z (about 8 years ago)
- Last Synced: 2025-05-07T10:11:24.796Z (8 months ago)
- Topics: iron, rust, webframework
- Language: Rust
- Size: 27.3 KB
- Stars: 9
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Iron Json Response
==================
[](https://travis-ci.org/sunng87/iron-json-response)
[](https://crates.io/crates/iron-json-response)
[](https://crates.io/crates/iron-json-response)
Middleware for json or jsonp response with [Iron
framework](http://ironframework.io). Using
[serde](https://github.com/serde-rs/json) for data type and
serialization.
Usage
-----
### Setup
Middleware setup:
```rust
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:
```rust
fn handler(req: &mut Request) -> IronResult {
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:
```rust
fn handler(req: &mut Request) -> IronResult {
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
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
### 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.