openapi-datetime/README.md
2025-09-22 16:06:54 +02:00

54 lines
1.2 KiB
Markdown

# FastAPI DateTime Service
This is a simple FastAPI application that provides an OpenAPI-compatible `/datetime` endpoint returning the current date, time, weekday, and calendar week.
## Features
- **OpenAPI Compatible**: Fully documented API with automatic OpenAPI documentation
- **Structured Response**: Returns time information in a consistent JSON format
- **Type Hints**: Uses Python type hints for better code clarity and IDE support
- **Comprehensive Documentation**: Detailed docstrings and OpenAPI metadata
## Requirements
- Python 3.7+
- FastAPI
- Uvicorn
```bash
pip install -r requirements.txt
```
## Running the Application
To start the FastAPI server, run:
```bash
python main.py
```
The server will be available at `http://localhost:8000`.
## Endpoints
### `GET /datetime`
Returns current date, time, weekday, and calendar week.
**Response Format:**
```json
{
"date": "2025-09-22",
"time": "14:30:45",
"weekday": "Monday",
"calendar_week": 38
}
```
**Response Fields:**
- `date` (string): Current date in YYYY-MM-DD format
- `time` (string): Current time in HH:MM:SS format
- `weekday` (string): Full weekday name (e.g., "Monday")
- `calendar_week` (integer): ISO calendar week number