API Reference - dlangkip/epidash GitHub Wiki

API Reference

This page documents the EpiDash API endpoints, request parameters, and response formats for developers who wish to integrate with or extend the dashboard.

Overview

The EpiDash API follows RESTful principles with JSON as the primary data format. All endpoints are located in the /api/ directory of the application.

Base URL

When running locally, the base URL is:

http://localhost/epidash/api/

For production deployments, replace with your domain:

https://your-domain.com/epidash/api/

Authentication

The current API implementation does not require authentication. If implementing in a production environment with sensitive data, consider adding appropriate authentication mechanisms.

API Endpoints

1. Get Epidemiological Data

Retrieves epidemiological data based on specified filters.

Endpoint

GET /get_data.php

Parameters

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.

Error Handling

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.

Cross-Origin Resource Sharing (CORS)

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

Rate Limiting

There is currently no rate limiting implemented. Consider adding rate limiting for production deployments.

Examples

Example: Fetching data using JavaScript

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;
  }
}

Example: Fetching data using PHP

<?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);

} ?>

Future API Enhancements

Planned API improvements for future versions:

  1. Authentication: Implement JWT or OAuth-based authentication
  2. Additional Endpoints: Add endpoints for saving user preferences and views
  3. Data Aggregation: Provide endpoints for pre-aggregated statistical data
  4. Versioning: Implement API versioning (e.g., /api/v1/...)
  5. Documentation: Implement Swagger/OpenAPI documentation
  6. 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.

⚠️ **GitHub.com Fallback** ⚠️