/rust-postgres

Rust Actix Web Server with PostgreSQL Database

Primary LanguageRust

Rust Postgres

This is a simple rust actix web server that connects to a postgres database.

Running the server

cargo run 

Running the Postgres database

docker run -it -d --name some-postgres -e POSTGRES_USER=test -e POSTGRES_PASSWORD=123 -p 5432:5432 postgres

Create database and table

docker exec -it some-postgres psql -U test
CREATE DATABASE rust_db;

\c rust_db


CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR NOT NULL,
    email VARCHAR NOT NULL
);

APIs

  1. Create User
curl -X POST -H "Content-Type: application/json" -d '{"name": "", "email": ""}' http://localhost:8080/create
  1. Get Users
curl -X GET http://localhost:8080/get_all
  1. Get User by ID
curl -X GET http://localhost:8080/get/:id
  1. Update User
curl -X PUT -H "Content-Type: application/json" -d '{"name": "", "email": ""}' http://localhost:8080/update/:id
  1. Delete User
curl -X DELETE http://localhost:8080/delete/:id