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

Add rocket for Rust #292

Open
andria-dev opened this issue Jan 19, 2024 · 0 comments
Open

Add rocket for Rust #292

andria-dev opened this issue Jan 19, 2024 · 0 comments

Comments

@andria-dev
Copy link

andria-dev commented Jan 19, 2024

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 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.


👍 reaction might help to get this request prioritized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants