Skip to main content

Introduction

The React Route Finder API is a RESTful Express backend service that provides route calculation and bus stop data for public transportation. The API enables clients to retrieve all available bus routes and calculate optimal paths between two geographic coordinates.

Base URL

The API server runs on port 8080 by default:
http://localhost:8080

Authentication

Currently, the API does not require authentication. All endpoints are publicly accessible.

Available Endpoints

The API provides two main endpoints:

Get All Routes

Retrieve all available bus stops and routes

Find Route

Calculate optimal route between two coordinates

Endpoint Summary

MethodEndpointDescription
GET/allRoutesReturns all bus stops organized by branch/route
POST/routeCalculates optimal route between origin and destination

Data Source

The API fetches bus stop data from an external Laravel service running on port 8000:
// src/server/ServerMockup.js:5
fetch("http://localhost:8000/branch")
The external service must be running for the API to function properly.

Response Format

All API responses are returned in JSON format. Successful responses contain the requested data, while errors return an object with an error property:
{
  "error": "Error message description"
}

Error Handling

The API implements graceful error handling for all endpoints. Common error scenarios include:
  • External service unavailable
  • Invalid request parameters
  • No routes found between coordinates
  • No bus stops within walking distance

Usage Patterns

Basic Fetch Example

// Fetch all routes
const response = await fetch('http://localhost:8080/allRoutes');
const busStops = await response.json();

// Find a route
const routeResponse = await fetch('http://localhost:8080/route', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    from: { lat: 40.7128, lng: -74.0060 },
    to: { lat: 40.7580, lng: -73.9855 }
  })
});
const route = await routeResponse.json();

Error Handling Pattern

try {
  const response = await fetch('http://localhost:8080/route', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(routeData)
  });
  
  const result = await response.json();
  
  if (result.error) {
    console.error('API Error:', result.error);
  } else {
    // Process successful response
    console.log('Route found:', result);
  }
} catch (error) {
  console.error('Network Error:', error);
}

Route Calculation Parameters

The route finding algorithm uses the following default parameters (defined in src/server/FindLogic.js:34-38):
ParameterValueDescription
walkKmh1 km/hWalking speed
busKmh60 km/hBus travel speed
busWaitH0.5 hoursAverage bus waiting time
maxWalkKm0.8 kmMaximum walking distance to/from stops
These parameters are used internally by the route calculation algorithm to determine optimal paths and walking distances.

Next Steps

Get All Routes

Learn how to retrieve bus stop data

Find Route

Learn how to calculate routes

Build docs developers (and LLMs) love