2.5 KiB
Demo Endpoint Implementation
Overview
A new endpoint /demo has been added to the OpenEventDatabase API. This endpoint serves an interactive HTML page with a MapLibre map that displays current events from the database.
Features
- Interactive MapLibre map showing current events
- Events are fetched from the
/eventendpoint with the current date - Each event is displayed as a marker on the map
- Clicking on a marker shows a popup with event details
- The map automatically zooms to fit all displayed events
- Sidebar with links to other API endpoints and the GitHub repository
Implementation Details
The implementation consists of the following components:
-
DemoResource Class: A new resource class in
oedb/resources/demo.pythat handles GET requests to the/demoendpoint and returns an HTML page. -
HTML Page: The HTML page includes:
- MapLibre JS and CSS libraries
- Custom CSS for styling the page
- A full-screen map
- A sidebar with information and links
-
JavaScript: The JavaScript code:
- Initializes a MapLibre map
- Fetches events from the
/eventendpoint - Displays events as markers on the map
- Creates popups with event details
- Fits the map view to include all events
-
Route Registration: The
/demoendpoint is registered inbackend.pywith the line:app.add_route('/demo', demo) -
Documentation: The root endpoint (
/) has been updated to include information about the demo endpoint.
How to Test
To test the demo endpoint:
-
Start the server:
python3 backend.py -
Open a web browser and navigate to:
http://127.0.0.1:8080/demo -
Verify that:
- The page loads correctly with a MapLibre map
- Events are displayed on the map (if there are events for the current date)
- Clicking on a marker shows a popup with event details
- Links to other endpoints work correctly
Troubleshooting
If no events appear on the map:
- Check if there are events for the current date in the database
- Try adding a test event using the
/eventendpoint - Check the browser console for any JavaScript errors
- Verify that the
/eventendpoint is working correctly by accessing it directly
Future Improvements
Potential future improvements for the demo page:
- Add date selection to view events from different dates
- Add filtering options (by event type, location, etc.)
- Add a search box to find specific events
- Improve the mobile experience
- Add more interactive features to the map