Skip to content

Instantly share code, notes, and snippets.

@mihneadb
Created January 20, 2017 00:44
Show Gist options
  • Save mihneadb/c9b17b5807b0b468dc7435333d5a4e25 to your computer and use it in GitHub Desktop.
Save mihneadb/c9b17b5807b0b468dc7435333d5a4e25 to your computer and use it in GitHub Desktop.
Hello world server in Rust using Iron and Params
extern crate iron;
extern crate params;
use iron::prelude::*;
use iron::status;
use params::{Params, Value};
fn handler(req: &mut Request) -> IronResult<Response> {
let params_map = req.get_ref::<Params>().unwrap();
let name = match params_map.find(&["name"]) {
Some(&Value::String(ref s)) => { s.clone() },
_ => String::from("world")
};
Ok(Response::with(
(status::Ok, format!("Hello, {}!", name))
))
}
fn main() {
Iron::new(handler).http("localhost:3000").unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment