Why would adding this package be useful?
Adding this package would allow Rust web server-related Kata to be authored. Without this, any web server challenges could only really be focused on the boilerplate code needed to create a basic web server and testing that would also be a pain. With Rocket, you not only get to focus on more realistic challenges, but you also get to test them more easily with both unit and integration tests.
Code Example
In this example, we create a simple web server that serves Hello, world! when visiting the / route. In the test section, we launch and track the Rocket server with a blocking client, and we test that it is a valid Rocket instance with expect. Once that's ready, we do a get request to the hello (/) route and check that the status is correct and the response is the correct value.
#[macro_use] extern crate rocket;
#[get("/")]
fn hello() -> &'static str {
"Hello, world!"
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![hello])
}
#[cfg(test)]
mod test {
use super::rocket;
use rocket::local::blocking::Client;
use rocket::http::Status;
#[test]
fn hello_world() {
let client = Client::tracked(rocket()).expect("valid rocket instance");
let mut response = client.get(uri!(super::hello)).dispatch();
assert_eq!(response.status(), Status::Ok);
assert_eq!(response.into_string().unwrap(), "Hello, world!");
}
}
An Aside
Rocket also has four other related packages: rocket_db_pools, rocket_dyn_templates, rocket_sync_db_pools, and rocket_ws. I believe that rocket_ws and rocket_dyn_templates could be very useful, but just the main rocket package would probably be a good start for now.
I would recommend also taking a look at Rocket's feature flags. At least json should be turned on.
:+1: reaction might help to get this request prioritized.
Package Information
Package name: rocket
Language name: Rust
Website: Homepage | Documentation
Why would adding this package be useful? Adding this package would allow Rust web server-related Kata to be authored. Without this, any web server challenges could only really be focused on the boilerplate code needed to create a basic web server and testing that would also be a pain. With Rocket, you not only get to focus on more realistic challenges, but you also get to test them more easily with both unit and integration tests.
Code Example
In this example, we create a simple web server that serves
Hello, world!
when visiting the/
route. In the test section, we launch and track the Rocket server with a blocking client, and we test that it is a valid Rocket instance withexpect
. Once that's ready, we do a get request to the hello (/
) route and check that the status is correct and the response is the correct value.An Aside
Rocket also has four other related packages: rocket_db_pools, rocket_dyn_templates, rocket_sync_db_pools, and rocket_ws. I believe that rocket_ws and rocket_dyn_templates could be very useful, but just the main rocket package would probably be a good start for now.
I would recommend also taking a look at Rocket's feature flags. At least
json
should be turned on.:+1: reaction might help to get this request prioritized.