A minimalist, high-performance microservice built with FastAPI to provide real-time date and time information for any valid IANA timezone. Perfect for distributed systems needing a reliable time reference.
- Python 3.9+
- pip (Python package manager)
- Clone the repository (or download the files):
git clone https://github.com/your-username/world-time-api.git
cd world-time-api
- Install dependencies:
pip install -r requirements.txt
- Run the application:
python main.py
*The server will start at http://127.0.0.1:8000*
Retrieves the current local time for a specific geographic region.
- Endpoint:
/time/{area}/{city} - Method:
GET - Parameters:
area(string): Continent or Ocean (e.g.,Europe,America,Asia)city(string): City name (e.g.,Berlin,New_York,Tokyo)
Example Request:
GET /time/Europe/Berlin
Success Response (200 OK):
{
"timezone": "Europe/Berlin",
"datetime": "2026-02-21 16:20:00",
"timestamp": 1771687200.0,
"iso": "2026-02-21T16:20:00+01:00"
}
Checks if the API is online and lists available routes.
- Endpoint:
/ - Method:
GET
FastAPI automatically generates beautiful, interactive documentation. While the server is running, you can test every endpoint directly in your browser:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
The API handles invalid timezone requests gracefully. If an incorrect area or city is provided, you will receive a descriptive error:
Error Response (404 Not Found):
{
"detail": "Timezone 'Mars/Base_Alpha' not found. Please use IANA format (e.g., Europe/London)."
}
This project is optimized for Railway. To deploy:
- Push this code to a GitHub repository.
- Create a New Project on Railway and select "Deploy from GitHub repo".
- Railway will automatically detect the
requirements.txtandProcfileto start the service.