Rust, Software Development

Rust REST API, Actix-web, PostgreSQL – Part 1: Overview

This post shows a simple example of a REST API with Rust, Actix-web, and PostgreSQL and its requirements.

Rust Actix-web PostgreSQL Requirements

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

  1. Windows 10
  2. Docker for Windows
    • Install Docker for Windows. These posts use Docker to create a PostgreSQL container.
  3. docker-compose.yml for PostgreSQL
  4. IntelliJ IDEA (optional)
    • Install the IntelliJ Rust plugin and create a new project.
  5. Rust 1.37.0
    • Install it via rustup-init.exe.

Moreover, we will need a database table in our PostgreSQL. We will use a single table called persons, and we can create it using the following DDL. To run the SQL DDL, we need an SQL editor (e.g., pgAdmin) that will allow us to connect to PostgreSQL and perform database changes.

Rust Update Cargo.toml

The three crates we will use for our Rust Actix-web PostgreSQL project are postgres, actix-web, and serde.

Here are some details about these Rust crates. Please take note of the specific versions we use in this example.

  1. Crate postgres
    • We need postgres for our Rust codes to access our PostgreSQL database, which runs in a Docker container.
  2. Crate actix-web
    • Actix-web is a framework for creating web applications with Rust. We can think of this framework as something similar to Spring-web from Spring and Java or Laravel for PHP.
  3. Crate serde
    • Serde is for the deserialization and serialization of HTTP requests and HTTP responses.

What’s Next For Our Rust Actix-web PostgreSQL

Next, we will talk about our Rust Actix-web PostgreSQL project structure overview.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like