4 releases

Uses old Rust 2015

0.1.3 Sep 7, 2016
0.1.2 Aug 6, 2016
0.1.1 Jul 15, 2016
0.1.0 Jul 12, 2016

#9 in #request-parameters

MIT license

5KB
81 lines

iron-params Build Status

Request parameters extension for the Iron web framework.

iron-params is a fast, convenient, and flexible extension for Iron Request. It allows retriving query/form params from iron request and convert into the type you want.

Example

extern crate iron;
extern crate iron_params as params;
use iron::prelude::*;
use params::*;

// To run, $ cargo run --example simple
// to use, $ curl -d "ids=1,2,3&channel=1" "http://localhost:3000/?ids=4,5,6,"

fn main() {
    let mut chain = Chain::new(handler);
    chain.link_before(params::Params {});
    Iron::new(chain).http("localhost:3000").unwrap();
}

fn handler(req: &mut Request) -> IronResult<Response> {
    let mut content = String::new();

    let ids = req.params("ids");
    content.push_str(&format!("ids:{:?}\n", ids));

    let channel = req.param::<i32>("channel");
    content.push_str(&format!("channel:{:?}\n", channel));

    let channel = req.param::<String>("channel");
    content.push_str(&format!("channel:{:?}\n", channel));

    let channel = req.param::<f32>("channel");
    content.push_str(&format!("channel:{:?}\n", channel));


    Ok(Response::with((iron::status::Ok, content)))
}

Installation

If you're using cargo, just add iron-params to your Cargo.toml.

[dependencies]

iron-params = "*"

Otherwise, cargo build, and the rlib will be in your target directory.

Examples

Dependencies

~5MB
~116K SLoC