Skip to content

acemcakmak/rest-api

Repository files navigation

User Management REST API

This project is a RESTful User Management service implementing basic CRUD operations:

  • Create a user
  • Update a user
  • Delete a user
  • Retrieve a single user
  • Retrieve all users

The service is implemented using FastAPI and PostgreSQL, follows a layered backend architecture, and is fully containerized with Docker. Database schema changes are handled via Alembic migrations. Input validation, error handling, and automated tests are included.


Tech Stack

Concern Technology
API Framework FastAPI
Database PostgreSQL
ORM SQLAlchemy 2.0
Migrations Alembic
Validation Pydantic
Password Hashing passlib (bcrypt)
Containerization Docker, docker-compose
Lint / Formatting Ruff
Testing Pytest

Requirements (pyproject.toml)

[project]
name = "rollic-case-study"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
  "fastapi>=0.110",
  "uvicorn[standard]>=0.27",
  "SQLAlchemy>=2.0",
  "psycopg[binary]>=3.1",
  "alembic>=1.13",
  "pydantic-settings>=2.2",
  "email-validator>=2.0",
  "bcrypt==4.0.1",
]


[project.optional-dependencies]
dev = [
  "pytest>=8.0",
  "httpx>=0.27",
  "ruff>=0.6",
]

[tool.ruff]
line-length = 100
target-version = "py311"

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-q"

Running and Using the Application with Sample Requests

Objective Command
Build and Start Services docker compose up --build -d
Apply Database Migrations docker compose exec api alembic upgrade head
Verify API is Running curl -i http://localhost:8080/users
Running Tests pytest

Add a User

curl -X PUT \
-d '{"name": "Test", "email": "test@example.com", "password": "securepasswd"}' \
-H 'Content-Type: application/json' \
http://localhost:8080/users
Status Code Description Sample Response
200 Success {"id": 1, "name": "Test", "email": "test@example.com"}
400 Bad request {"error": "Bad request"}
403 Email already exists {"error": "User with that email already exists"}
500 Server error {"error": "server error"}

Edit a User's Attributes

curl -X PATCH \
-d '{"name": "No name", "password": "strongpasswd"}' \
-H 'Content-Type: application/json' \
http://localhost:8080/users/1
Status Code Description Sample Response
200 Success {"id": 1,"name": "No name", "email": "test@example.com"}
400 Bad request {"error": "Bad request"}
404 If user not found {"error": "User with that id does not exist"}
500 Server error {"error": "server error"}

Delete a User

curl -X DELETE http://localhost:8080/users/1
Status Code Description Sample Response
200 Success
404 If user not found {"error": "User with that id does not exist"}
500 Server error {"error": "server error"}

Find User with ID

curl -X GET http://localhost:8080/users/1
Status Code Description Sample Response
200 Success {"id": 1, "name": "No name", "email": "test@example.com"}
404 If user not found {"error": "User with that id does not exist"}
500 Server error {"error": "server error"}

Get All Users

curl -X GET http://localhost:8080/users
Status Code Description Sample Response
200 Success [{"id": 1, "name": "No name", "email": "test@example.com"}]
500 Server error {"error": "server error"}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors