Skip to main content
GET
/
allRoutes
Get All Routes
curl --request GET \
  --url http://localhost:8080/allRoutes
{
  "branches": [
    {
      "id": 123,
      "name": "<string>",
      "stops": [
        {
          "id": 123,
          "branch_id": 123,
          "name": "<string>",
          "latitude": 123,
          "longitude": 123
        }
      ]
    }
  ]
}

Overview

The /allRoutes endpoint returns comprehensive data about all available bus stops organized by branch (route line). This endpoint is typically called once at application startup to populate the map and route planning system.

Endpoint

GET /allRoutes

Request

This endpoint does not require any parameters.

Headers

No special headers are required.

Response

The endpoint returns an array of branch objects, where each branch represents a bus route line with its associated stops.
branches
array
required
Array of branch objects representing different bus routes

Success Response Example

[
  {
    "id": 1,
    "name": "Route 101",
    "stops": [
      {
        "id": 1,
        "branch_id": 1,
        "name": "Main Street Station",
        "latitude": 40.7128,
        "longitude": -74.0060
      },
      {
        "id": 2,
        "branch_id": 1,
        "name": "Central Park Stop",
        "latitude": 40.7580,
        "longitude": -73.9855
      }
    ]
  },
  {
    "id": 2,
    "name": "Route 202",
    "stops": [
      {
        "id": 3,
        "branch_id": 2,
        "name": "Downtown Terminal",
        "latitude": 40.7589,
        "longitude": -73.9851
      }
    ]
  }
]

Error Response

If the external data service is unavailable or an error occurs:
{
  "error": "Error message describing what went wrong"
}

Code Examples

curl http://localhost:8080/allRoutes

Implementation Details

The endpoint implementation (src/server/server.js:17-24):
app.get("/allRoutes", (req, resp) => {
    ServerMockup()
        .then(busStopsData => resp.json(busStopsData))
        .catch((err) => {
            console.error(err)
            resp.json({ error: err.message })
        })
})

Data Flow

  1. Client sends GET request to /allRoutes
  2. Server calls ServerMockup() to fetch data from external service
  3. External Laravel service returns branch and stop data
  4. Server forwards the data as JSON response
  5. On error, server returns error object
The external Laravel service at http://localhost:8000/branch must be running for this endpoint to function.

Error Handling

Always check for the error property in the response:
const response = await fetch('http://localhost:8080/allRoutes');
const data = await response.json();

if (data.error) {
  // Handle error case
  console.error('API returned error:', data.error);
  // Show user-friendly message
  showNotification('Unable to load bus routes. Please try again.');
} else {
  // Process successful response
  displayRoutesOnMap(data);
}

Use Cases

Display All Stops on Map

async function loadAndDisplayRoutes() {
  const routes = await fetch('http://localhost:8080/allRoutes')
    .then(r => r.json());
  
  routes.forEach(branch => {
    branch.stops.forEach(stop => {
      addMarkerToMap({
        lat: stop.latitude,
        lng: stop.longitude,
        title: stop.name,
        routeName: branch.name
      });
    });
  });
}

Count Total Stops

const routes = await fetch('http://localhost:8080/allRoutes')
  .then(r => r.json());

const totalStops = routes.reduce((count, branch) => 
  count + branch.stops.length, 0
);

console.log(`Total stops across all routes: ${totalStops}`);

Find Stops Near Location

function findNearbyStops(routes, userLat, userLng, maxDistance = 0.8) {
  const allStops = routes.flatMap(branch => branch.stops);
  
  return allStops.filter(stop => {
    const distance = calculateDistance(
      userLat, userLng, 
      stop.latitude, stop.longitude
    );
    return distance <= maxDistance;
  });
}

Find Route

Calculate optimal path between coordinates

API Overview

View all available endpoints

Build docs developers (and LLMs) love