Sitemap

Rocket | 05, Query Parameter

Oct 20, 2026

--

Let’s add query parameter to a route path.

Get Mike Code’s stories in your inbox

Join Medium for free to get updates from this writer.

(Youtube Video)

use rocket::{  get, routes};


#[rocket::main]
async fn main() {
rocket::build().mount("/", routes![index, hello]).launch().await.unwrap();
}

#[get("/")]
fn index( ) -> String {
"Home".to_string()
}

#[get("/hello?<name>&<age>")]
fn hello(name: String, age: usize) -> String {
format!("person name : {} , age : {}", name, age)
}

In hello handler , to add query parameter to the path , it will start with ? ,then query parameter’s name in a pair of angle brackets , to add more parameters , we use & to separate each parameter.

In handler , we add parameters , whose name need to be the same as the name in the angle backets.

--

--