0

REST API with Rust, Actix-web, and PostgreSQL – Part 1

This is the first part post that demonstrates a simple example of a REST API with Rust, Actix-web and PostgreSQL.

Prerequisites

These are the items used for this posts and the subsequent ones.

1. Windows 10

Please see How to install Rust in Windows 10

2. Docker for Windows

Install Docker for Windows. These posts use Docker to create PostgreSQL container.

3. docker-compose.yml for PostgreSQL

Please see docker-compose.yml for PostgreSQL. The same username and password are used for the codes.

4. Database Table

We use a single table called persons. Create the table using the DDL below.

5. IntelliJ IDEA

Install the IntelliJ Rust plugin and create a new project.

6. Rust 1.37.0

Install it via rustup-init.exe .

Update Cargo.toml

The three crates in used are – postgres, actix-web, and serde.

postgres

We need postgres to access our PostgreSQL database running as a Docker container.

actix-web

Actix-web is a framework for creating web applications with Rust. This is like Spring-web from Spring and Java.

serde

Serde is for the deserialization and serialization of HTTP requests and HTTP responses, respectively.

Karl San Gabriel

Karl San Gabriel

Professional Software Developer