Build a CRUD API with Rust

Sean Wragg
Sean’s Blog
Published in
9 min readMar 19, 2018

--

Since my initial Node/Rust REST comparison, I’ve wanted to follow up with a comprehensive guide for getting simple CRUD operations up and running in Rust.

While Rust has its complexities, coming from Node.js, one thing that’s kept me attracted to the language is its simplicity. It’s sleek and strikes a great balance between safety and cognitive intuition.

In any event, hopefully this guide helps those that are new to Rust and encourages those who are on the fence.

Scroll down if you’d like to see how Rust compares against Java and Node.js

Major frameworks used

  • Rocketweb framework for writing fast web applications
  • Serdeframework for serializing and deserializing Rust data structures
  • Dieselsafe, extensible ORM and query builder

Creating our application in Rust

First, we’ll create a new Rust project using the commands below.

[sean@lappy486:~] $ cargo new hero-api --bin && cd hero-api
Created binary (application) `hero-api` project

Before we move forward though, Rocket requires us to use the nightly Rust build. Thankfully, there’s a quick command we can use to switch channels.

$ rustup default nightly
$ rustup update && cargo update

You’ll get some output here regarding the switch but, can confirm it was successful by…

--

--

Sean Wragg
Sean Wragg

Written by Sean Wragg

Writing about code, comics, and fhqwhgads!

Responses (14)