Rocket (web framework)

Last updated
Rocket
Developer Sergio Benitez [1]
Initial release2016;10 years ago (2016)
Stable release
0.5.1 [2]   OOjs UI icon edit-ltr-progressive.svg / 23 May 2024;19 months ago (23 May 2024)
Repository github.com/rwf2/Rocket
Written in Rust
Operating system Linux, macOS, Windows, FreeBSD, OpenBSD
Type Web framework
License MIT License or Apache License
Website rocket.rs

Rocket is a web framework written in Rust. [3] [4] It supports handling HTTP requests, Web Sockets, JSON, templating, and more. Its design was inspired by Rails, Flask, Bottle, and Yesod. [5] It is dually licensed under the MIT License and the Apache License.

Contents

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 attached to it. The function will define code that should respond to an HTTP request. The macro that is written as part of the function declaration 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.

Example

This is an example of a working rocket application:

#[macro_use]externcraterocket;#[get("/hello/<name>/<age>")]fnhello(name:&str,age:u8)->String{format!("Hello, {} year old named {}!",age,name)}#[launch]fnrocket()->_{rocket::build().mount("/",routes![hello])}

Sending an HTTP GET request to /hello/John/50 would return the following response:

Hello, 50 year old named John!.

Features

Rocket implements the following features:

References

  1. "Sergio Benitez - Who Am I?". sergio.bz. Retrieved 2020-05-30.
  2. "Release 0.5.1". 23 May 2024. Retrieved 25 May 2024.
  3. Schlothauer, Sarah (December 14, 2018). "Speedy Rust framework for web apps burns through the sky". JAXenter. Retrieved May 29, 2020.
  4. Ekwuno, Obinna (October 18, 2019). "The best Rust frameworks to check out in 2019". LogRocket. Retrieved May 29, 2020.
  5. "Introduction - Rocket Programming Guide". rocket.rs. Retrieved 2020-05-30.