Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tzilist committed Nov 9, 2018
1 parent f2edc44 commit 383b581
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/string_vec_extractors.rs → examples/body_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#![feature(async_await, futures_api)]

#[macro_use]
extern crate serde_derive;
use tide::body;

#[derive(Serialize, Deserialize, Clone, Debug)]
struct Message {
author: Option<String>,
contents: String,
}

async fn echo_string(msg: String) -> String {
println!("String: {}", msg);
format!("{}", msg)
Expand All @@ -11,9 +21,16 @@ async fn echo_vec(msg: Vec<u8>) -> String {
String::from_utf8(msg).unwrap()
}

async fn echo_json(msg: body::Json<Message>) -> body::Json<Message> {
println!("JSON: {:?}", msg.0);

msg
}

fn main() {
let mut app = tide::App::new(());
app.at("/echo/string").post(echo_string);
app.at("/echo/vec").post(echo_vec);
app.at("/echo/json").post(echo_json);
app.serve("127.0.0.1:8000");
}

0 comments on commit 383b581

Please sign in to comment.