Skip to content

alperencubuk/fastapi-celery-redis-postgres-docker-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Celery Redis Postgres Docker REST API

Summary:

This is simple REST API project using a modern stack with FastAPI.
Celery for background tasks
Redis for the message broker
PostgreSQL for the database
SqlAlchemy for ORM
Docker for containerization
Docker Compose for defining and running multi-container

Summary


Endpoints Table:

Request URL Description HTTP
/users/{count} Get random user data from randomuser.me/api and add database using Celery. (Delay = 10 sec) POST
/users/{count}/{delay} Get random user data from randomuser.me/api and add database using Celery. POST
/users/{user_id} Get user from database. GET
/weathers/{city} Get weather data from api.collectapi.com/weather and add database using Celery. (Delay = 10 sec) POST
/weathers/{city}/{delay} Get weather data from api.collectapi.com/weather and add database using Celery. POST
/weathers/{city} Get weather from database. GET
/tasks/{task_id} Get task status. GET

Requirements:

  • Docker and Docker Compose

How to Run:

docker-compose up --build

Example Requests:


Request:

POST /users/10

Response:

{
    "task_id": "44178ce4-6f7a-4a6b-97fd-0de72a055360"
}

Request:

GET /users/5

Response:

{
    "first_name": "Lorenzo",
    "last_name": "Domínguez"
}

Request:

POST /weathers/erzincan

Response:

{
    "task_id": "46f5f77a-5fd7-41dd-898b-235d5def4a70"
}

Request:

GET /weathers/erzincan

Response:

{
    "erzincan": [
        {
            "date": "08.10.2022",
            "day": "Cumartesi",
            "description": "orta şiddetli yağmur",
            "degree": 26.02
        },
        {
            "date": "09.10.2022",
            "day": "Pazar",
            "description": "hafif yağmur",
            "degree": 18.59
        },
        {
            "date": "10.10.2022",
            "day": "Pazartesi",
            "description": "açık",
            "degree": 17.85
        },
        {
            "date": "11.10.2022",
            "day": "Salı",
            "description": "açık",
            "degree": 17.49
        },
        {
            "date": "12.10.2022",
            "day": "Çarşamba",
            "description": "kapalı",
            "degree": 17.42
        },
        {
            "date": "13.10.2022",
            "day": "Perşembe",
            "description": "hafif yağmur",
            "degree": 19.42
        },
        {
            "date": "14.10.2022",
            "day": "Cuma",
            "description": "hafif yağmur",
            "degree": 16.37
        }
    ]
}

Request:

GET /tasks/46f5f77a-5fd7-41dd-898b-235d5def4a70

Response:

{
    "state": "SUCCESS"
}

Alperen Cubuk

About

This is simple REST API project using a modern stack with FastAPI. (Celery, Redis, Postgres, SQLAlchemy, Docker, Docker Compose)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published