Back to articles
Rocket Has a Free API — Rust Web Framework That Writes Itself

Rocket Has a Free API — Rust Web Framework That Writes Itself

via Dev.to WebdevAlex Spinov

Rocket is a Rust web framework focused on developer experience. With macro-based routing, built-in form handling, and templating — Rocket makes Rust web development feel as easy as Python. Why Rocket? Macro-based routing — routes defined with #[get] , #[post] attributes Type-safe — request guards validate before your handler runs Built-in — forms, JSON, templates, cookies, sessions Async — fully async since Rocket 0.5 Quick Start cargo new myapp && cd myapp cargo add rocket --features json #[macro_use] extern crate rocket ; use rocket :: serde :: json :: Json ; use serde ::{ Serialize , Deserialize }; #[derive(Serialize, Deserialize)] struct Message { content : String , } #[get( "/" )] fn index () -> & 'static str { "Hello, Rocket!" } #[get( "/hello/<name>" )] fn hello ( name : & str ) -> Json < Message > { Json ( Message { content : format! ( "Hello, {}!" , name ), }) } #[post( "/messages" , data = "<msg>" )] fn create ( msg : Json < Message > ) -> Json < Message > { msg } #[launch] f

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles