This project is a REST API service built with FastAPI for viewing salary information. It includes authentication mechanisms to ensure that only authorized users can access sensitive salary data.
- User Authentication
- Retrieve Current Salary
- Retrieve Date of Next Salary Increase
- Secure Endpoints with JWT Token
- GNU Make
- Docker and Docker Compose
- Python 3.12 with Poetry
-
Clone the repository
-
Set up the environment variables:
Set variables in
.env
file if neededPOSTGRES_DB=yourdbname POSTGRES_USER=yourdbuser POSTGRES_PASSWORD=yourdbpassword POSTGRES_SERVER=localhost
-
Install dependencies:
poetry install
-
Build and start the Docker containers:
make up
-
Access the API:
The API will be available at
http://localhost:8000
Endpoint | Description |
---|---|
POST /user |
Create new user |
POST /login |
Get access token for a user |
GET /salary |
Get salary information |
- URL:
/user
- Method:
POST
- Request Body:
{ "username": "testuser", "email": "[email protected]", "password": "securepassword", "salary": 50000, "promotion_date": "2024-05-17T00:00:00" }
- Response:
201 Created
- URL:
/login
- Method:
POST
- Request Body:
{ "username": "testuser", "password": "securepassword" }
- Response:
{ "access_token": "access_token", "token_type": "bearer" }
- URL:
/salary
- Method:
GET
- Headers:
Authorization: Bearer access_token
- Response:
{ "salary": 50000, "promotion_date": "2024-05-17T00:00:00" }
curl -X POST "http://localhost:8000/user" -H "Content-Type: application/json" -d '{
"username": "testuser",
"email": "[email protected]",
"password": "securepassword",
"salary": 50000,
"promotion_date": "2024-05-17T00:00:00"
}'
curl -X POST "http://localhost:8000/auth/login" -H "Content-Type: application/json" -d '{
"username": "testuser",
"password": "securepassword"
}'
curl -X GET "http://localhost:8000/salary" \
-H "Authorization: Bearer <access_token>"
You can find more useful commands if you run
make help