Rocket (web framework) explained

Rocket
Developer:Sergio Benitez[1]
Programming Language:Rust
Operating System:Linux, macOS, Windows, FreeBSD, OpenBSD
Genre:Web framework
License:MIT License or Apache License

Rocket is a web framework written in Rust.[2] [3] It supports handling HTTP requests, Web Sockets, JSON, templating, and more. Its design was inspired by Rails, Flask, Bottle, and Yesod.[4] It is dually licensed under the MIT License and the 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 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:

  1. [macro_use] extern crate rocket;
  2. [get("/hello/<name>/<age>")]

fn hello(name: &str, age: u8) -> String

  1. [launch]

fn rocket -> _ Sending an HTTP GET request to /hello/John/20 would return the following response:

Hello, 20 year old named John!.

Features

Rocket implements the following features:

  1. [get("/")]

fn index -> &'static str

Notes and References

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