From 3d1afc4c5a4eafdba1a46ad4f2a95585140d801d Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Fri, 21 Jan 2022 15:20:23 -0800 Subject: [PATCH] Remove (now outdated) http-api.md spec document Signed-off-by: Erik Hollensbe --- http-api.md | 58 ----------------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 http-api.md diff --git a/http-api.md b/http-api.md deleted file mode 100644 index 455090a..0000000 --- a/http-api.md +++ /dev/null @@ -1,58 +0,0 @@ -## http API idea - -```rust -async fn root(req: Request) -> Result { - Ok(Response::builder() - .status(StatusCode::OK) - .body("hello, world!") - .build()?) -} - -async fn with_param(req: Request, params: Params) -> Result { - let param = params.get("param")?; - Ok(Response::builder() - .status(StatusCode::OK) - .body(&format!("hello, {}!", param)) - .build()?) -} - -async fn with_param_post(req: Request, params: Params) -> Result { - let param = params.get("param")?; - let body = req.body().await?; // should also support iter() probably for large requests - Ok(Response::builder() - .status(StatusCode::OK) - .body(&format!("hello, {}!\n{}\n", param, body)) - .build()?) -} - -#[derive(Clone, Debug)] -struct ToggleMiddleware { - state: AtomicBool, -} - -#[async_trait] -impl Middleware for ToggleMiddleware { - async fn perform( - &mut self, - req: Request, - params: Params, - next: Next, - ) -> Result { - self.state.swap(self.state.get(), Ordering::Relaxed); - let response = next.call(req).await?; - let headers = response.headers_mut(); - headers.insert("state", &format!("{:?}", self.state.get())); - Ok(response) - } -} - -#[tokio::main] -async fn main() { - let mut app = Server::new(); - app.with(ToggleMiddleware::new()); - app.get("/", root); - app.get("/:param", with_param); - app.post("/:param", with_param_post); - app.listen("127.0.0.1:3000"); -} -```