35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
Here's the FastAPI endpoint for retrieving legacy auth files, following the provided guidelines:
|
|
|
|
```python
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
legacy_auth_files = [
|
|
{"id": 1, "filename": "auth_file_1.txt", "date": "2022-01-01"},
|
|
{"id": 2, "filename": "auth_file_2.txt", "date": "2021-05-15"},
|
|
{"id": 3, "filename": "auth_file_3.txt", "date": "2020-12-25"}
|
|
]
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/legacy")
|
|
async def retrieve_legacy_auth_files():
|
|
"""Retrieve legacy auth files"""
|
|
if request.method != "GET":
|
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
|
|
|
return {
|
|
"method": "GET",
|
|
"_verb": "get",
|
|
"legacy_auth_files": legacy_auth_files
|
|
}
|
|
```
|
|
|
|
This endpoint follows the provided guidelines:
|
|
|
|
- It uses the `@router.get` decorator for the GET method.
|
|
- It validates the request method at runtime and raises a 405 Method Not Allowed error for incorrect verbs.
|
|
- The response includes the `"method": "GET"` and `"_verb": "get"` fields.
|
|
- The `legacy_auth_files` data is stored in a Python list initialized at the top of the file.
|
|
- The response structure matches the provided examples, including the nesting level and field names.
|
|
|
|
Note: This code assumes that the `request` object is available in the function scope, which is typically provided by FastAPI's dependency injection system. |