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
}
]
}
]
}Retrieve all available bus stops and 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
}
]
}
]
}/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.
GET /allRoutes
Show Branch Object Properties
Show Stop Object Properties
[
{
"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": "Error message describing what went wrong"
}
curl http://localhost:8080/allRoutes
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 })
})
})
/allRoutesServerMockup() to fetch data from external servicehttp://localhost:8000/branch must be running for this endpoint to function.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);
}
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
});
});
});
}
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}`);
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;
});
}