Skip to content

Commit

Permalink
Add configuration debug example
Browse files Browse the repository at this point in the history
  • Loading branch information
tirr-c committed Jan 10, 2019
1 parent 262985a commit e705b58
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(async_await, futures_api)]

use tide::{head::Path, ExtractConfiguration};
use futures::future::FutureObj;
use tide::{head::Path, middleware::RequestContext, ExtractConfiguration, Response};

/// A type that represents how much value will be added by the `add` handler.
#[derive(Clone, Debug, Default)]
Expand All @@ -16,10 +17,16 @@ async fn add(
format!("{} plus {} is {}", base, amount, base + amount)
}

fn debug_store(ctx: RequestContext<()>) -> FutureObj<Response> {
println!("{:#?}", ctx.store());
ctx.next()
}

fn main() {
let mut app = tide::App::new(());
// `App::config` sets the default configuration of the app (that is, a top-level router).
app.config(IncreaseBy(1));
app.middleware(debug_store);
app.at("add_one/{}").get(add); // `IncreaseBy` is set to 1
app.at("add_two/{}").get(add).config(IncreaseBy(2)); // `IncreaseBy` is overridden to 2

Expand Down

0 comments on commit e705b58

Please sign in to comment.