Created
September 18, 2016 12:20
-
-
Save mre/3d4de4fcbfb2448707ad557204244cda to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #[macro_use] extern crate nickel; | |
| use std::collections::BTreeMap; | |
| use nickel::status::StatusCode; | |
| use nickel::{Nickel, JsonBody, HttpRouter, MediaType}; | |
| #[derive(Clone)] | |
| struct Person { | |
| first_name: String, | |
| last_name: String, | |
| } | |
| fn speak_name(person: Person) -> String { | |
| person.first_name | |
| } | |
| fn main() { | |
| let mut server = Nickel::new(); | |
| let person = Person { first_name: "Otto".into(), last_name: "Waalkes".into() }; | |
| server.get("/:first/:last", middleware! { |req| | |
| speak_name(person.clone()) | |
| }); | |
| server.listen("127.0.0.1:6767"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment