Skip to main content

Report Incident

curl -X POST https://autonomous.stu.nighthawkcodingsociety.com/api/incidents \
  -H "Content-Type: application/json" \
  -d '{
    "location": "Poway Rd & Civic Center Dr",
    "type": "accident",
    "details": "Two-car collision blocking right lane"
  }'
Reports a new traffic incident to help other drivers and autonomous vehicles navigate safely.

Request Body

location
string
required
Street name or intersection where the incident occurred
type
string
required
Type of incident. Common values:
  • accident - Vehicle collision
  • blockage - Road obstruction
  • construction - Construction zone
  • hazard - Road hazard (debris, potholes, etc.)
  • weather - Weather-related issue
details
string
Optional additional information about the incident

Response

message
string
Confirmation message
id
number
Unique identifier for the reported incident
timestamp
string
ISO 8601 timestamp when the incident was reported

Success Response

{
  "message": "Incident reported successfully",
  "id": 123,
  "timestamp": "2026-03-04T15:30:00Z"
}

Error Response

{
  "error": "Location is required"
}

Get Recent Incidents

curl https://autonomous.stu.nighthawkcodingsociety.com/api/incidents \
  -H "Content-Type: application/json"
Retrieves a list of recent traffic incidents in the Poway area.

Response

Returns an array of incident objects, sorted by most recent first.
[].id
number
Unique incident identifier
[].location
string
Street or intersection location
[].type
string
Type of incident (accident, blockage, construction, hazard, weather)
[].details
string
Additional information about the incident (may be empty)
[].timestamp
string
ISO 8601 timestamp when reported
[].status
string
Current status: active, resolved, or expired

Success Response

[
  {
    "id": 123,
    "location": "Poway Rd & Civic Center Dr",
    "type": "accident",
    "details": "Two-car collision blocking right lane",
    "timestamp": "2026-03-04T15:30:00Z",
    "status": "active"
  },
  {
    "id": 122,
    "location": "Community Rd",
    "type": "construction",
    "details": "Lane closure for roadwork",
    "timestamp": "2026-03-04T14:00:00Z",
    "status": "active"
  }
]

Empty Response

When no active incidents:
[]

Real Implementation

From navigation/traffic.html:73-103:

Reporting an Incident

document.getElementById('incidentForm').addEventListener('submit', async (e) => {
  e.preventDefault();
  const location = document.getElementById('location').value;
  const type = document.getElementById('type').value;
  const details = document.getElementById('details').value;

  const res = await fetch('https://autonomous.stu.nighthawkcodingsociety.com/api/incidents', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ location, type, details })
  });

  const data = await res.json();
  document.getElementById('statusMessage').innerText = data.message || 'Incident reported.';
  document.getElementById('incidentForm').reset();
  loadIncidents(); // refresh list
});

Loading Recent Incidents

async function loadIncidents() {
  const res = await fetch('https://autonomous.stu.nighthawkcodingsociety.com/api/incidents');
  const data = await res.json();

  const list = document.getElementById('incidentList');
  list.innerHTML = '';
  data.forEach((incident) => {
    list.innerHTML += `<li><strong>${incident.type}</strong> at <em>${incident.location}</em><br>${incident.details || ''}</li>`;
  });
}

loadIncidents();

Use Cases

Traffic Awareness

Display real-time incidents on navigation maps to help drivers avoid problem areas.

Route Planning

Integrate with the Routes API to automatically avoid streets with active incidents.

Autonomous Vehicle Safety

Provide incident data to autonomous vehicle systems for safer navigation decisions.

Community Reporting

Allow users to contribute to a shared incident database for improved traffic awareness.

Auto-Refresh Pattern

For real-time updates, implement polling:
// Refresh incidents every 30 seconds
setInterval(loadIncidents, 30000);

Incident Lifecycle

  • Active: Recently reported and currently affecting traffic
  • Resolved: Incident has been cleared
  • Expired: Automatically marked expired after 2 hours with no updates
Only active incidents are typically displayed in navigation interfaces.

Build docs developers (and LLMs) love