Technology Stack:
- Python
This project recreates the FastAPI translation sample using Django. It exposes a single endpoint that returns a localized greeting with an ISO-8601 timestamp appended.
- Python 3.10 or newer
- pip
- Installation - Create a virtual environment and install the development dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.txt- Running the Tests
python -m pytest- Starting the Service
python manage.py runserverThe server listens on port 8080 by default. Override the PORT environment variable if needed.
- HTTP Endpoint
GET /– Responds with a greeting string such ashello world @ 2024-06-01T12:34:56+00:00.GET /eggs– 🥚 See below.
- Configuration Environment variables provide the same configurability as the FastAPI version:
TRANSLATION_DEFAULT_LANGUAGE(default:EN) – Two-letter code used to choose the greeting.TRANSLATION_FILE(default:translations.json) – File located in theresources/directory that contains the greeting map.PORT(default:8080) – Port for the HTTP server.
All translations are stored in resources/translations.json, copied verbatim from the FastAPI project.
- Find the easter egg riddle, steps below:
Start the service first with the 3. Start development server task, then ask it for the riddle at /eggs.
Leave the server task running and open a second terminal (Terminal > New Terminal). That terminal runs in the same container as the server, so localhost works here:
curl http://localhost:8080/eggs- 🥚 Find the four translation easter eggs
"The translation file holds 85 greetings, but the service knows a few it never wrote down. Pirates can read them."
You will know you found it when the service hands you a trophy. 🏆
House rules: reading app/easter_eggs.py is cheating (and it is encoded anyway). The response headers, however, are fair game. 🐣