Skip to content

Optional Path parameter #2874

Answered by robjtede
qarmin asked this question in Q&A
Discussion options

You must be logged in to vote
#[get("/patient-info/{eye}")]
pub async fn AAAA(
    pool: web::Data<DbPool>,
    path: web::Path<String>,
) -> anyhow::Result<HttpResponse, Error> {
    Ok(HttpResponse::Ok().body("ABCD"))
}

Though Option<String> will not work here. You'll need two handlers and a delegate method. Eg:

#[get("/patient-info")]
pub async fn aaa(
    pool: web::Data<DbPool>,
    path: web::Path<String>,
) -> Result<HttpResponse, Error> {
  aaaa_inner(&pool, None)
}

#[get("/patient-info/{eye}")]
pub async fn aaaa_eye(
    pool: web::Data<DbPool>,
    path: web::Path<String>,
) -> Result<HttpResponse, Error> {
  aaaa_inner(&pool, Some(path.into_inner()))
}

async fn aaaa_inner(pool: &DbPool, path: Option<String>)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by qarmin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants