Skip to content

Commit 32cf6a7

Browse files
authored
Merge pull request #344 from http-rs/page2
Rewind page 2
2 parents 333e69d + fc85f20 commit 32cf6a7

25 files changed

+1111
-68
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ serde_json = "1.0.41"
3232
typemap = "0.3.3"
3333
serde_urlencoded = "0.6.1"
3434
log = "0.4.8"
35+
accept-encoding = "0.2.0-alpha.2"
36+
async-compression = "0.1.0-alpha.7"
3537

3638
[dependencies.http-service-hyper]
3739
optional = true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ and **not ready for production use yet**.
5454
fn main() -> Result<(), std::io::Error> {
5555
let mut app = tide::App::new();
5656
app.at("/").get(|_| async move { "Hello, world!" });
57-
Ok(app.serve("127.0.0.1:8000")?)
57+
Ok(app.run("127.0.0.1:8000")?)
5858
}
5959
```
6060

examples/body_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ fn main() {
4343
app.at("/echo/json").post(echo_json);
4444
app.at("/echo/form").post(echo_form);
4545

46-
app.serve("127.0.0.1:8000").unwrap();
46+
app.run("127.0.0.1:8000").unwrap();
4747
}

examples/catch_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ async fn echo_path(cx: Context<()>) -> String {
88
fn main() {
99
let mut app = tide::App::new();
1010
app.at("/echo_path/*path").get(echo_path);
11-
app.serve("127.0.0.1:8000").unwrap();
11+
app.run("127.0.0.1:8000").unwrap();
1212
}

examples/cookies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ fn main() {
2222
app.at("/").get(retrieve_cookie);
2323
app.at("/set").get(set_cookie);
2424
app.at("/remove").get(remove_cookie);
25-
app.serve("127.0.0.1:8000").unwrap();
25+
app.run("127.0.0.1:8000").unwrap();
2626
}

examples/default_headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fn main() {
1111

1212
app.at("/").get(|_| async move { "Hello, world!" });
1313

14-
app.serve("127.0.0.1:8000").unwrap();
14+
app.run("127.0.0.1:8000").unwrap();
1515
}

examples/graphql.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ use juniper::graphql_object;
88
use std::sync::{atomic, Arc};
99
use tide::{error::ResultExt, response, App, Context, EndpointResult};
1010

11-
// First, we define `Data` that holds accumulator state. This is accessible as App data in
11+
// First, we define `State` that holds accumulator state. This is accessible as App data in
1212
// Tide, and as executor context in Juniper.
1313
#[derive(Clone, Default)]
14-
struct Data(Arc<atomic::AtomicIsize>);
14+
struct State(Arc<atomic::AtomicIsize>);
1515

16-
impl juniper::Context for Data {}
16+
impl juniper::Context for State {}
1717

1818
// We define `Query` unit struct here. GraphQL queries will refer to this struct. The struct itself
1919
// doesn't have any associated data (and there's no need to do so), but instead it exposes the
2020
// accumulator state from the context.
2121
struct Query;
2222

23-
graphql_object!(Query: Data |&self| {
23+
graphql_object!(Query: State |&self| {
2424
// GraphQL integers are signed and 32 bits long.
2525
field accumulator(&executor) -> i32 as "Current value of the accumulator" {
2626
executor.context().0.load(atomic::Ordering::Relaxed) as i32
@@ -31,7 +31,7 @@ graphql_object!(Query: Data |&self| {
3131
// `Query`, but it provides the way to "mutate" the accumulator state.
3232
struct Mutation;
3333

34-
graphql_object!(Mutation: Data |&self| {
34+
graphql_object!(Mutation: State |&self| {
3535
field add(&executor, by: i32) -> i32 as "Add given value to the accumulator." {
3636
executor.context().0.fetch_add(by as isize, atomic::Ordering::Relaxed) as i32 + by
3737
}
@@ -43,7 +43,7 @@ type Schema = juniper::RootNode<'static, Query, Mutation>;
4343

4444
// Finally, we'll bridge between Tide and Juniper. `GraphQLRequest` from Juniper implements
4545
// `Deserialize`, so we use `Json` extractor to deserialize the request body.
46-
async fn handle_graphql(mut cx: Context<Data>) -> EndpointResult {
46+
async fn handle_graphql(mut cx: Context<State>) -> EndpointResult {
4747
let query: juniper::http::GraphQLRequest = cx.body_json().await.client_err()?;
4848
let schema = Schema::new(Query, Mutation);
4949
let response = query.execute(&schema, cx.state());
@@ -58,7 +58,7 @@ async fn handle_graphql(mut cx: Context<Data>) -> EndpointResult {
5858
}
5959

6060
fn main() {
61-
let mut app = App::with_state(Data::default());
61+
let mut app = App::with_state(State::default());
6262
app.at("/graphql").post(handle_graphql);
63-
app.serve("127.0.0.1:8000").unwrap();
63+
app.run("127.0.0.1:8000").unwrap();
6464
}

examples/hello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
22
let mut app = tide::App::new();
33
app.at("/").get(|_| async move { "Hello, world!" });
4-
app.serve("127.0.0.1:8000").unwrap();
4+
app.run("127.0.0.1:8000").unwrap();
55
}

examples/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ fn main() {
6666
let mut app = App::with_state(Database::default());
6767
app.at("/message").post(new_message);
6868
app.at("/message/:id").get(get_message).post(set_message);
69-
app.serve("127.0.0.1:8000").unwrap();
69+
app.run("127.0.0.1:8000").unwrap();
7070
}

examples/multipart-form/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async fn upload_file(mut cx: Context<()>) -> EndpointResult {
5757
fn main() {
5858
let mut app = App::new();
5959
app.at("/upload_file").post(upload_file);
60-
app.serve("127.0.0.1:8000").unwrap();
60+
app.run("127.0.0.1:8000").unwrap();
6161
}
6262

6363
// Test with:

0 commit comments

Comments
 (0)