Added api post.
This commit is contained in:
parent
38af08eb14
commit
ce10c73eae
22
src/main.rs
22
src/main.rs
@ -3,7 +3,7 @@ use axum::{
|
|||||||
extract::{Extension, FromRequestParts, State},
|
extract::{Extension, FromRequestParts, State},
|
||||||
http::request::Parts,
|
http::request::Parts,
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::get,
|
routing::{get, post},
|
||||||
RequestPartsExt, Router,
|
RequestPartsExt, Router,
|
||||||
};
|
};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
@ -45,6 +45,7 @@ async fn main() {
|
|||||||
async fn create_app(state: MoreThanText) -> Router {
|
async fn create_app(state: MoreThanText) -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(mtt_conn))
|
.route("/", get(mtt_conn))
|
||||||
|
.route("/api/:document", post(mtt_conn))
|
||||||
.layer(CookieManagerLayer::new())
|
.layer(CookieManagerLayer::new())
|
||||||
.layer(Extension(state.clone()))
|
.layer(Extension(state.clone()))
|
||||||
.with_state(state)
|
.with_state(state)
|
||||||
@ -96,6 +97,7 @@ mod servers {
|
|||||||
body::Body,
|
body::Body,
|
||||||
http::{
|
http::{
|
||||||
header::{COOKIE, SET_COOKIE},
|
header::{COOKIE, SET_COOKIE},
|
||||||
|
Method,
|
||||||
Request, StatusCode,
|
Request, StatusCode,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -170,4 +172,22 @@ mod servers {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user