-
pub struct AppState { pub struct User { /// HTTP请求参数提取示例 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
What..? I don’t speak Chinese sorry |
Beta Was this translation helpful? Give feedback.
-
He just wrote a request parameter extract example, nothing special. pub struct AppState<T, V> {
redis: Arc<T>,
mysql: Arc<V>,
}
pub struct User {
pub id: i64,
pub name: String,
}
/// HTTP request parameter extract example
/// GET request: https://example.com/orders/user/:id?page=1&page_per=15
pub fn example<S, B>(
Path(user_id): Path<String>,
Query(pagination): Query<HashMap<String, usize>>,
http_header: HeaderMap,
State(state): State<S>,
request: Request<B>,
) -> impl IntoResponse {
// wish this example can help rookies like me
// see more details: https://docs.rs/axum/0.6.11/axum/extract/index.html
let user = request.extensions().get::<String>();
let host = http_header.get("host");
todo!()
} |
Beta Was this translation helpful? Give feedback.
He just wrote a request parameter extract example, nothing special.