Rust, Software Development

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

Photo by Mike from Pexels

Previously, we had a bit of an overview of the stuff needed to start creating a REST API example. This post is the second part post.

Rust Project Structure

Our project structure looks like this.

This is the main file that has the main()  function. It uses the person module.

person module

This contains the struct s for our example.

This contains functions for our basic CRUD operations against an instance of PostgreSQL.



This URL creates a new person in the database.

  • HTTP POST   /persons that accept a JSON with a single field person_name .

Retrieve – Get All and Get by Person ID

These URLs retrieves a list of persons or a single person based on person_id .

  • HTTP GET   /persons
  • HTTP GET  /persons/{person_id}


This URL updates an existing person’s name.

  • HTTP PUT   /persons/{person_id}  that accepts a JSON with person_name .


This URL deletes an existing person.

  • HTTP DELETE  /persons/{person_id}

You Might Also Like