API Reference - dlangkip/epidash GitHub Wiki
This page documents the EpiDash API endpoints, request parameters, and response formats for developers who wish to integrate with or extend the dashboard.
The EpiDash API follows RESTful principles with JSON as the primary data format. All endpoints are located in the /api/
directory of the application.
When running locally, the base URL is:
http://localhost/epidash/api/
For production deployments, replace with your domain:
https://your-domain.com/epidash/api/
The current API implementation does not require authentication. If implementing in a production environment with sensitive data, consider adding appropriate authentication mechanisms.
Retrieves epidemiological data based on specified filters.
GET /get_data.php
Parameter | Type | Required | Description |
---|---|---|---|
source | string | No | Data source to use: 'mock', 'database', or 'both'. Defaults to value in config. |
start_date | string | No | Start date in format YYYY-MM-DD. Defaults to 2023-01-01. |
end_date | string | No | End date in format YYYY-MM-DD. Defaults to 2023-12-31. |
disease | string | No | Filter by disease name. |
region | string | No | Filter by region name. |
The API returns appropriate HTTP status codes along with JSON error messages:
- 200: Successful request
- 400: Bad request (invalid parameters)
- 404: Resource not found
- 405: Method not allowed
- 500: Server error
Error responses include an "error" field with a descriptive message.
CORS is enabled by default for the API. This can be configured in the .env
file:
ENABLE_CORS=true
The API sets the following headers when CORS is enabled:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: Content-Type
There is currently no rate limiting implemented. Consider adding rate limiting for production deployments.
async function fetchEpidemicData() {
try {
const response = await fetch('http://your-domain.com/epidash/api/get_data.php?source=mock&disease=Malaria');
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
console.log('Fetched data:', data);
return data;
} catch (error) {
console.error('Error fetching data:', error);
throw error;
}
}
<?php
function fetchEpidemicData() {
$url = 'http://your-domain.com/epidash/api/get_data.php?source=mock&disease=Malaria';
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => 'GET'
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response === false) {
throw new Exception("Error fetching data");
}
return json_decode($response, true);
}
?>
Planned API improvements for future versions:
- Authentication: Implement JWT or OAuth-based authentication
- Additional Endpoints: Add endpoints for saving user preferences and views
- Data Aggregation: Provide endpoints for pre-aggregated statistical data
- Versioning: Implement API versioning (e.g., /api/v1/...)
- Documentation: Implement Swagger/OpenAPI documentation
- Caching: Add response caching for improved performance
For any questions or issues related to the API, please create an issue on the GitHub repository or contact the developer directly.