From ce10c73eaee864863d8afd4f24cbddc48c25c4cd Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Wed, 23 Apr 2025 10:46:33 -0400 Subject: [PATCH] Added api post. --- src/main.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 10c39e8..90799f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use axum::{ extract::{Extension, FromRequestParts, State}, http::request::Parts, response::IntoResponse, - routing::get, + routing::{get, post}, RequestPartsExt, Router, }; use clap::Parser; @@ -45,6 +45,7 @@ async fn main() { async fn create_app(state: MoreThanText) -> Router { Router::new() .route("/", get(mtt_conn)) + .route("/api/:document", post(mtt_conn)) .layer(CookieManagerLayer::new()) .layer(Extension(state.clone())) .with_state(state) @@ -96,6 +97,7 @@ mod servers { body::Body, http::{ header::{COOKIE, SET_COOKIE}, + Method, Request, StatusCode, }, }; @@ -170,4 +172,22 @@ mod servers { .unwrap(); assert_eq!(response.status(), StatusCode::NOT_FOUND); } + + #[tokio::test] + async fn add_new_page() { + let base = "/something"; + let api = "/api".to_owned() + base; + let app = create_app(MoreThanText::new()).await; + let response = app + .oneshot( + Request::builder() + .method(Method::POST) + .uri(&api) + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap(); + assert_eq!(response.status(), StatusCode::OK, "failed to post ro {:?}", api); + } }