https://github.com/root27/rust-postgres
Rust Actix Web Server with PostgreSQL Database
https://github.com/root27/rust-postgres
Last synced: over 1 year ago
JSON representation
Rust Actix Web Server with PostgreSQL Database
- Host: GitHub
- URL: https://github.com/root27/rust-postgres
- Owner: root27
- Created: 2024-02-18T11:52:24.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T08:53:13.000Z (about 2 years ago)
- Last Synced: 2025-01-10T08:58:40.414Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 78.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust Postgres
This is a simple rust actix web server that connects to a postgres database.
## Running the server
```bash
cargo run
```
## Running the Postgres database
```bash
docker run -it -d --name some-postgres -e POSTGRES_USER=test -e POSTGRES_PASSWORD=123 -p 5432:5432 postgres
```
## Create database and table
```bash
docker exec -it some-postgres psql -U test
```
```sql
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
```bash
curl -X POST -H "Content-Type: application/json" -d '{"name": "", "email": ""}' http://localhost:8080/create
```
2. Get Users
```bash
curl -X GET http://localhost:8080/get_all
```
3. Get User by ID
```bash
curl -X GET http://localhost:8080/get/:id
```
4. Update User
```bash
curl -X PUT -H "Content-Type: application/json" -d '{"name": "", "email": ""}' http://localhost:8080/update/:id
```
5. Delete User
```bash
curl -X DELETE http://localhost:8080/delete/:id
```