Better Programming

Advice for programmers.

Follow publication

Member-only story

How to Build a REST API in Rust — A Step-by-Step Guide

Asel Siriwardena
Better Programming
Published in
5 min readApr 17, 2020

--

Mozilla Rust

Hello, I’m Asel. Today, I am going to show you how to create a simple REST API in Rust.

For that, we are going to use the Rocket framework for the API and Diesel ORM framework for persisting features. This framework will cover all the things mentioned below. So, it will be much easier than implementing it from scratch.

  • Start a web server and open a PORT.
  • Listen to requests on this PORT.
  • If a request comes in, look at the Path in the HTTP header.
  • Route the request to the handler according to the Path.
  • Help you extract the information from the request.
  • Pack the generated data (created by you) and form a response.
  • Send the response back to the sender.

Installing Rust Nightly

Because Rocket makes abundant use of Rust’s syntax extensions and other advanced, unstable features, we have to install nightly.

rustup default nightly

--

--

Asel Siriwardena
Asel Siriwardena

Written by Asel Siriwardena

Software Engineer | University of Westminster | Robert Gordon University

Write a response