This article may rely excessively on sources
too closely associated with the subject, potentially preventing the article from being
verifiable and
neutral. (December 2023) |
Developer(s) | Sergio Benitez [1] |
---|---|
Initial release | 2016 |
Stable release | 0.5.1
[2]
/ 23 May 2024 |
Repository |
github |
Written in | Rust |
Operating system | Linux, macOS, Windows, FreeBSD, OpenBSD |
Type | Web framework |
License | MIT License or Apache License |
Website |
rocket |
Rocket is a web framework written in Rust. [3] [4] It supports HTTP requests, Web Sockets JSON, templating and more. Its design was inspired by Rails, Flask, Bottle, and Yesod. [5] It licensed under MIT License or Apache License.
To create a web server with Rocket, the user will define an application, then use the "mount" function to attach "routes" to it. Each "route" is a rust function with a macro attched to it. The function will define code that should response to an HTTP request. The macro that is written as part of the function decleration will define which HTTP Method (such as GET, POST, PUT, etc.) it should be handle, as well as a pattern describing the URL it should be relevant to.
This is an example of a working rocket application:
#[macro_use] extern crate rocket;
#[get("/hello/<name>/<age>")]
fn hello(name: &str, age: u8) -> String {
format!("Hello, {} year old named {}!", age, name)
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes!hello])
}
Sending an HTTP GET request to /hello/John/20 would return the following response:
Hello, 20 year old named John!
.
Rocket implements the following features:
/hello
route with "Hello World":#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}