oedb-backend/oedb/resources/root.py
2025-09-15 23:54:04 +02:00

49 lines
No EOL
1.6 KiB
Python

"""
Root resource for the OpenEventDatabase.
"""
import falcon
from oedb.utils.serialization import dumps
from oedb.utils.logging import logger
class RootResource:
"""
Resource for the root endpoint.
Handles the / endpoint.
"""
def on_get(self, req, resp):
"""
Handle GET requests to the / endpoint.
Returns a JSON response with available routes and a welcome message.
Args:
req: The request object.
resp: The response object.
"""
logger.info("Processing GET request to /")
try:
# Create a response with available routes and a welcome message
response = {
"message": "Welcome to the OpenEventDatabase API!",
"available_routes": {
"/": "This endpoint - provides information about available routes",
"/event": "Get events matching specified criteria",
"/event/{id}": "Get a specific event by ID",
"/event/search": "Search for events using a GeoJSON geometry",
"/stats": "Get statistics about the database"
}
}
# Set the response body and status
resp.text = dumps(response)
resp.status = falcon.HTTP_200
logger.success("Successfully processed GET request to /")
except Exception as e:
logger.error(f"Error processing GET request to /: {e}")
resp.status = falcon.HTTP_500
resp.text = dumps({"error": str(e)})
# Create a global instance of RootResource
root = RootResource()