Web service with Rust, Rocket and Diesel

A hands-on walk-trough on how to create a REST-API with Rust, Rocket and Diesel

Marco Amann
Feb 14, 2020 · 12 min read
Rocket, ready to launch. Photo by Felipe Simo on Unsplash

What and why

Creating the API

Ecosystem overview

Starting the Rocket

Rocket is a web framework for Rust that makes it simple to write fast, secure web applications without sacrificing flexibility, usability, or type safety.

version = "0.4.2"
features = ["private-cookies"]
default-features = false
features = ["json", "diesel_postgres_pool", "serve"]
fn hello(name: String) -> String {
format!("hello {}", name)
fn super_secure_function(id: i32, user: AuthUser) -> ... {
#[post("/stay", data = "<new_stay>")]
fn stay_new(new_stay: Json<NewStay>, con: DbCon) -> ... {

Connecting the Database

A rusty barrel full of diesel? (also resembling the shape of a DB in a flowchart?) Photo by Aleks Dorohovich on Unsplash

Diesel basics

fn stay_get_by_id(con: DbCon, id: i32) -> ...{


Photo by Leonel Fernandez on Unsplash



Digital Frontiers — Das Blog

Dies ist das Blog der Digital Frontiers GmbH & Co.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store