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

How to define multiple methods (GET/HEAD/OPTIONS) for same method #827

Closed
nbari opened this issue Dec 29, 2023 · 2 comments · Fixed by #1006
Closed

How to define multiple methods (GET/HEAD/OPTIONS) for same method #827

nbari opened this issue Dec 29, 2023 · 2 comments · Fixed by #1006
Labels
enhancement New feature or request

Comments

@nbari
Copy link

nbari commented Dec 29, 2023

I have an endpoint (/health) that accepts GET,HEAD,OPTIONS, this compiles but only uses the last one (HEAD):

#[utoipa::path(
    get,
    path= "/health",
    responses (
        (status = 200, description = "Database connection is healthy", body = [Health]),
        (status = 503, description = "Database connection is unhealthy", body = [Health])
    ),
    head,
    path= "/health",
    responses (
        (status = 200, description = "Database connection is healthy"),
        (status = 503, description = "Database connection is unhealthy")
    )
)]
// axum handler for health
#[instrument]
pub async fn health(method: Method, pool: Extension<PgPool>) -> impl IntoResponse {
    debug!(method = ?method, "HTTP request method: {}", method);
    ...

How could I manage this without duplicating the method fn health_get, fn health_head, fn health_options?

@BSteffaniak
Copy link

BSteffaniak commented Jul 23, 2024

I'd like to see this too.

Example handler that handles both GET and HEAD for actix:

#[route("/track", method = "GET", method = "HEAD")]
pub async fn track_endpoint(
    req: HttpRequest,
    query: web::Query<GetTrackQuery>,
    api_state: web::Data<MusicApiState>,
) -> Result<HttpResponse> {
    ...

@juhaku juhaku added the enhancement New feature or request label Aug 24, 2024
@juhaku
Copy link
Owner

juhaku commented Aug 24, 2024

Good idea. Let's evaluate possibilities and see if this can be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants