Table of Contents

API Design

Traffic Elf uses simple PHP-based JSON APIs.

Design Goals


Example: Clients API

Endpoint:

/api/clients.php
<?php
require 'db.php';
 
$stmt = $pdo->query("SELECT * FROM clients ORDER BY name");
echo json_encode($stmt->fetchAll());

Example: Campaigns API

Endpoint:

/api/campaigns.php
<?php
require 'db.php';
 
$stmt = $pdo->query("SELECT * FROM campaigns ORDER BY start_date DESC");
echo json_encode($stmt->fetchAll());

Frontend Usage

fetch('/api/clients.php')
  .then(res => res.json())
  .then(data => renderGrid(data));