A RESTful API built with FastAPI, PostgreSQL, and Docker to fetch and store weather data from the OpenWeather API.
- 🐍 Python 3.11
- ⚡ FastAPI
- 🐘 PostgreSQL
- 🐳 Docker & Docker Compose
- 🌐 OpenWeather API
wait-for-it.sh file uses Unix-style (LF) line endings.
If edited in Windows, convert the file using VS Code (bottom-right corner -> select "LF") or a tool like dos2unix.
This ensures compatibility when running inside the Docker container (Linux environment).
git clone https://github.com/your-username/gntech-test-carlos.git
cd gntech-test-carlosCreate a .env file in the root directory (an example is available in .env.example):
POSTGRES_USER=carlos
POSTGRES_PASSWORD=carlos123
POSTGRES_DB=weather_db
OPENWEATHER_API_KEY=your_api_key_here
DATABASE_URL=postgresql://carlos:carlos123@db:5432/weather_dbYou can get your free OpenWeather API key at: https://openweathermap.org/api
docker-compose up --buildAfter the project is running, visit:
-
GET /weather
Returns all weather data stored in the database. -
POST /weather?city=CityName
Fetches weather data for the specified city from OpenWeather, stores it in the database, and returns a success message.
POST http://localhost:8000/weather?city=London
GET http://localhost:8000/weatherYou can also run the main.py script manually to insert a city and fetch its weather data:
docker exec -it gntech-api bashpython main.pyTechnical Test — GNTech 2025