Hi, welcome to Axum-Postgres, a basic CRUD (Create, Read, Update, Delete) application built with Rust's Axum web framework and PostgreSQL. This project provides a simple API for managing tasks, demonstrating the integration of Axum with a PostgreSQL database.
Here is the YouTube video associated with this repo: https://youtu.be/NJsTgmayHZY
- Prerequisites
- Setup
- Database Configuration
- Run the Application
- API Endpoints
- Project Structure
- Contributing
- License
Make sure you have the following installed on your system:
- Rust (https://www.rust-lang.org/tools/install)
- PostgreSQL (https://www.postgresql.org/download/)
- Clone the repository:
git clone https://github.com/CudiLala/Rust-axum-postgres-CRUD-app.git
cd Rust-axum-postgres-CRUD-app
- Build binaries
cargo build
- Database Configuration
Create a PostgreSQL database and user by executing the following SQL commands in your PostgreSQL shell or client:
-- create user
CREATE ROLE axum_postgres WITH LOGIN PASSWORD 'axum_postgres';
-- create database
CREATE DATABASE axum_postgres WITH OWNER = 'axum_postgres';
-- in your axum_postgres database
-- create task table
CREATE TABLE tasks (
task_id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
priority INT
);
Copy the contents of the create.sql
file and execute it in your PostgreSQL database.
Create a .env
file in the project root and configure the DATABASE_URL
and SERVER_ADDRESS
:
DATABASE_URL=postgres://axum_postgres:axum_postgres@127.0.0.1:5432/axum_postgres
SERVER_ADDRESS=127.0.0.1:7878
- Run the application Run the application with
cargo run
GET /tasks
Retrieves a list of all tasks.
POST /tasks
Content-Type: application/json
{
"name": "Task Name",
"priority": 1
}
Creates a new task.
PATCH /tasks/{task_id}
Content-Type: application/json
{
"name": "New Task Name",
"priority": 2
}
Updates an existing task.
DELETE /tasks/{task_id}
Feel free to contribute by opening issues or creating pull requests. Your feedback and contributions are highly appreciated.
This project is licensed under the CC0 License.