Skip to content

Commit

Permalink
Middleware docs (LukeMathWalker#216)
Browse files Browse the repository at this point in the history
As it happens, while writing doc examples I uncovered a few more bugs
that slipped through the tests I had written so far.
  • Loading branch information
LukeMathWalker authored Mar 24, 2024
1 parent af78d02 commit d3542f8
Show file tree
Hide file tree
Showing 155 changed files with 2,732 additions and 781 deletions.
30 changes: 0 additions & 30 deletions doc_examples/guide/middleware/core_concepts/project-signalers.snap

This file was deleted.

28 changes: 0 additions & 28 deletions doc_examples/guide/middleware/core_concepts/project/src/mw.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
```rust title="src/order2.rs" hl_lines="7 8 9"
```rust title="src/order1/blueprint.rs" hl_lines="9"
use pavex::blueprint::router::GET;
use pavex::blueprint::Blueprint;
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(f!(crate::first));
bp.route(GET, "/", f!(crate::handler));
bp.wrap(f!(crate::second)); // (1)!
bp.wrap(f!(crate::wrap1));
bp.route(GET, "/", f!(super::handler));
bp.wrap(f!(crate::wrap2));
bp
}
```
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
```rust title="src/order3.rs" hl_lines="7 8 9"
```rust title="src/order2/blueprint.rs" hl_lines="9"
use pavex::blueprint::router::GET;
use pavex::blueprint::Blueprint;
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(f!(crate::first)); // (1)!
bp.wrap(f!(crate::wrap1));
bp.nest(nested());
bp.wrap(f!(crate::second)); // (2)!
bp.wrap(f!(crate::wrap2));
bp
}
pub fn nested() -> Blueprint {
let mut bp = Blueprint::new();
bp.route(GET, "/", f!(crate::handler));
bp.route(GET, "/", f!(super::handler));
bp
}
```
15 changes: 15 additions & 0 deletions doc_examples/guide/middleware/order/project-post_and_wrap.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```rust title="src/post_and_wrap/blueprint.rs"
use pavex::blueprint::{Blueprint, router::GET};
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.post_process(f!(crate::post1));
bp.wrap(f!(crate::wrap1));
bp.post_process(f!(crate::post2));
bp.route(GET, "/", f!(super::handler));
bp
}
```
14 changes: 14 additions & 0 deletions doc_examples/guide/middleware/order/project-post_only.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```rust title="src/post_only/blueprint.rs"
use pavex::blueprint::{Blueprint, router::GET};
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.post_process(f!(crate::post1));
bp.post_process(f!(crate::post2));
bp.route(GET, "/", f!(super::handler));
bp
}
```
16 changes: 16 additions & 0 deletions doc_examples/guide/middleware/order/project-pre_and_post.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```rust title="src/pre_and_post/blueprint.rs"
use pavex::blueprint::{Blueprint, router::GET};
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.pre_process(f!(crate::pre1));
bp.post_process(f!(crate::post1));
bp.post_process(f!(crate::post2));
bp.pre_process(f!(crate::pre2));
bp.route(GET, "/", f!(super::handler));
bp
}
```
17 changes: 17 additions & 0 deletions doc_examples/guide/middleware/order/project-pre_and_wrap.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```rust title="src/pre_and_wrap/blueprint.rs"
use pavex::blueprint::{Blueprint, router::GET};
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.pre_process(f!(crate::pre1));
bp.wrap(f!(crate::wrap1));
bp.pre_process(f!(crate::pre2));
bp.wrap(f!(crate::wrap2));
bp.pre_process(f!(crate::pre3));
bp.route(GET, "/", f!(super::handler));
bp
}
```
14 changes: 14 additions & 0 deletions doc_examples/guide/middleware/order/project-pre_only.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```rust title="src/pre_only/blueprint.rs"
use pavex::blueprint::{Blueprint, router::GET};
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.pre_process(f!(crate::pre1));
bp.pre_process(f!(crate::pre2));
bp.route(GET, "/", f!(super::handler));
bp
}
```
18 changes: 18 additions & 0 deletions doc_examples/guide/middleware/order/project-registration.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```rust title="src/core/blueprint.rs"
use pavex::blueprint::router::GET;
use pavex::blueprint::Blueprint;
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.pre_process(f!(crate::pre1));
bp.post_process(f!(crate::post1));
bp.wrap(f!(crate::wrap1));
bp.pre_process(f!(crate::pre2));
bp.post_process(f!(crate::post2));
bp.route(GET, "/", f!(super::handler));
bp
}
```
14 changes: 14 additions & 0 deletions doc_examples/guide/middleware/order/project-wrap_only.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```rust title="src/wrap_only/blueprint.rs"
use pavex::blueprint::{Blueprint, router::GET};
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(f!(crate::wrap1));
bp.wrap(f!(crate::wrap2));
bp.route(GET, "/", f!(super::handler));
bp
}
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "mw_core"
name = "order"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "mw_core_server_sdk"
name = "order_server_sdk"
version = "0.1.0"
edition = "2021"

[package.metadata.px.generate]
generator_type = "cargo_workspace_binary"
generator_name = "mw_core"
generator_name = "order"
15 changes: 15 additions & 0 deletions doc_examples/guide/middleware/order/project/src/blueprint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use pavex::blueprint::Blueprint;

pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.nest(crate::core::blueprint());
bp.nest_at("/pre_only", crate::pre_only::blueprint());
bp.nest_at("/post_only", crate::post_only::blueprint());
bp.nest_at("/wrap_only", crate::wrap_only::blueprint());
bp.nest_at("/pre_and_post", crate::pre_and_post::blueprint());
bp.nest_at("/post_and_wrap", crate::post_and_wrap::blueprint());
bp.nest_at("/pre_and_wrap", crate::pre_and_wrap::blueprint());
bp.nest_at("/order1", crate::order1::blueprint());
bp.nest_at("/order2", crate::order2::blueprint());
bp
}
16 changes: 16 additions & 0 deletions doc_examples/guide/middleware/order/project/src/core/blueprint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use pavex::blueprint::router::GET;
use pavex::blueprint::Blueprint;
use pavex::f;

pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();

bp.pre_process(f!(crate::pre1));
bp.post_process(f!(crate::post1));
bp.wrap(f!(crate::wrap1));
bp.pre_process(f!(crate::pre2));
bp.post_process(f!(crate::post2));
bp.route(GET, "/", f!(super::handler));

bp
}
5 changes: 5 additions & 0 deletions doc_examples/guide/middleware/order/project/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub use blueprint::blueprint;
pub use routes::handler;

mod blueprint;
mod routes;
16 changes: 16 additions & 0 deletions doc_examples/guide/middleware/order/project/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(dead_code)]
#![allow(unused_variables)]
pub use blueprint::blueprint;

mod blueprint;
pub mod core;
pub mod order1;
pub mod order2;
pub mod post_only;
pub mod pre_only;
pub mod wrap_only;
pub mod pre_and_post;
pub mod pre_and_wrap;
pub mod post_and_wrap;
mod mw;
pub use mw::*;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::error::Error;

use cargo_px_env::generated_pkg_manifest_path;
use mw_core::blueprint;
use order::blueprint;
use pavex_cli_client::Client;

fn main() -> Result<(), Box<dyn Error>> {
Expand Down
42 changes: 42 additions & 0 deletions doc_examples/guide/middleware/order/project/src/mw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use pavex::middleware::{Next, Processing};
use pavex::response::Response;
use std::future::IntoFuture;

pub async fn wrap1<C>(next: Next<C>) -> Response
where
C: IntoFuture<Output = Response>,
{
next.await
}

pub async fn wrap2<C>(next: Next<C>) -> Response
where
C: IntoFuture<Output = Response>,
{
next.await
}

pub async fn pre1() -> Processing
{
Processing::Continue
}

pub async fn pre2() -> Processing
{
Processing::Continue
}

pub async fn pre3() -> Processing
{
Processing::Continue
}

pub async fn post1(response: Response) -> Response
{
response
}

pub async fn post2(response: Response) -> Response
{
response
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use pavex::f;

pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(f!(crate::first));
bp.wrap(f!(crate::second));
bp.route(GET, "/", f!(crate::handler));
bp.wrap(f!(crate::wrap1));
bp.route(GET, "/", f!(super::handler));
bp.wrap(f!(crate::wrap2));
bp
}
5 changes: 5 additions & 0 deletions doc_examples/guide/middleware/order/project/src/order1/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub use blueprint::blueprint;
pub use routes::handler;

mod blueprint;
mod routes;
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use pavex::f;

pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(f!(crate::first)); // (1)!
bp.wrap(f!(crate::wrap1));
bp.nest(nested());
bp.wrap(f!(crate::second)); // (2)!
bp.wrap(f!(crate::wrap2));
bp
}

pub fn nested() -> Blueprint {
let mut bp = Blueprint::new();
bp.route(GET, "/", f!(crate::handler));
bp.route(GET, "/", f!(super::handler));
bp
}
5 changes: 5 additions & 0 deletions doc_examples/guide/middleware/order/project/src/order2/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub use blueprint::blueprint;
pub use routes::handler;

mod blueprint;
mod routes;
Loading

0 comments on commit d3542f8

Please sign in to comment.