Skip to content

GET, POST等参数提取 #1860

Answered by foxsin10
weq95 asked this question in Q&A
Mar 17, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

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::<S…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@davidpdrsn
Comment options

@foxsin10
Comment options

@davidpdrsn
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1859 on March 17, 2023 07:12.