Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add extractor functions with better API than extract #1859

Merged
merged 3 commits into from
Oct 7, 2023
Merged

feat: add extractor functions with better API than extract #1859

merged 3 commits into from
Oct 7, 2023

Conversation

gbj
Copy link
Collaborator

@gbj gbj commented Oct 7, 2023

The extract functions in the Actix and Axum integrations took me a while to figure out, and the API is okay but not great. There's actually a much simpler way to do the same thing. This PR adds an extractor function, which is generic over some extractable T type and returns it. This supports tuples, etc. as well.

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Search {
    q: String,
}

// Actix
#[server]
pub async fn query_extract() -> Result<Search, ServerFnError> {
    use actix_web::web::Query;
    use leptos_actix::extractor;

    let Query(query) = extractor().await?;
    Ok(query)
}

// Axum
#[server]
pub async fn data() -> Result<Search, ServerFnError> {
    use axum::extract::Query;
    use leptos_axum::extractor;
    
    let Query(query) = extractor().await?;
    Ok(query)
}

@gbj gbj merged commit 0d4862b into main Oct 7, 2023
56 checks passed
@gbj gbj deleted the 1755 branch October 7, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant