migrated to axum 0.6
This commit is contained in:
parent
42bfc2540b
commit
3c17e1fd3b
3 changed files with 111 additions and 45 deletions
|
|
@ -2,7 +2,8 @@ use axum::{
|
|||
routing::{get, post},
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
Json, Router, Extension,
|
||||
extract::{Json, State},
|
||||
Router,
|
||||
};
|
||||
use tower_http::{cors::{CorsLayer, Any}, compression::CompressionLayer, trace::TraceLayer};
|
||||
use http::{Method, header::CONTENT_TYPE};
|
||||
|
|
@ -34,7 +35,7 @@ struct RequestParams {
|
|||
ids: Vec<u32>,
|
||||
}
|
||||
|
||||
async fn get_url(Json(req): Json<RequestParams>, Extension(state): Extension<Arc<RwLock<APIClient>>>) -> impl IntoResponse {
|
||||
async fn get_url(State(state): State<Arc<RwLock<APIClient>>>, Json(req): Json<RequestParams>) -> impl IntoResponse {
|
||||
if req.formats.is_empty() {
|
||||
return (StatusCode::BAD_REQUEST, "Format list cannot be empty".to_string());
|
||||
}
|
||||
|
|
@ -91,7 +92,7 @@ async fn main() {
|
|||
let app = Router::new()
|
||||
.route("/", get(root))
|
||||
.route("/get_url", post(get_url))
|
||||
.layer(Extension(shared_state))
|
||||
.with_state(shared_state)
|
||||
.layer(cors)
|
||||
.layer(CompressionLayer::new())
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue