Created
January 20, 2017 00:44
-
-
Save mihneadb/c9b17b5807b0b468dc7435333d5a4e25 to your computer and use it in GitHub Desktop.
Hello world server in Rust using Iron and Params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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