Route API

All endpoints require a Firebase ID token in the Authorization: Bearer <token> header. A missing or invalid token returns 401 UNAUTHORIZED.


Get Saved Route

GET /route/:rideId/:direction/:routeNumber

Auth: Bearer token (Firebase ID token)

Returns a previously computed route stored in Firestore. The caller must be a ride creator, admin, or participant with an accepted RSVP.

Path Parameters

Parameter Type Description
rideId string ID of the ride the route belongs to
direction "to" \| "from" Route direction: to = origin → destination; from = destination → origin
routeNumber number 0-based alternative index; use 0 for the default route

Implementation status: Both direction: "to" and direction: "from" are persisted when computed via POST /route. All alternatives returned by the Google Routes API (at indices 0, 1, 2, etc.) are stored for each direction.

Response 200

The full route document — see Route Schema for the complete shape.

{
  "distanceMeters": 425000,
  "staticDuration": { "seconds": 18000, "nanos": 0 },
  "legs": [/* Leg[] */],
  "viewport": { "high": {/* LatLng */}, "low": {/* LatLng */} },
  "routeLabels": ["DEFAULT_ROUTE"],
}

Errors

Status Code Condition
401 UNAUTHORIZED No valid Firebase ID token
403 FORBIDDEN Caller is not a creator, admin, or participant of the ride
404 RIDE_NOT_FOUND Ride with :rideId does not exist
404 ROUTE_NOT_FOUND Route for the given direction/routeNumber combination does not exist

Compute Routes

POST /route

Auth: Bearer token (Firebase ID token)

Calls the Google Routes API and returns all computed route alternatives. If rideId is provided and the caller is the ride creator or admin, all computed alternatives are automatically saved to rides/{rideId}/routes/{direction}-{index}.

Implementation status: This endpoint accepts direction: "to" or direction: "from" and computes all alternatives. If rideId is provided and the caller is the ride creator or admin, all alternatives for that direction are persisted to Firestore and retrievable via the GET endpoint.

Request

{
  "origin": {
    "location": { "latLng": { "latitude": 12.9716, "longitude": 77.5946 } }, // null if using placeId
    "placeId": "ChIJ...", // null if using location
  },
  "destination": {
    "location": { "latLng": { "latitude": 15.3647, "longitude": 75.1240 } },
    "placeId": null,
  },
  "intermediates": [], // optional; array of Waypoint objects
  "direction": "to", // optional; default "to"
  "rideId": "ride_abc123", // optional; if provided + caller is creator/admin, routes are saved
  "optimizeWaypointOrder": false, // optional; default false
  "highQuality": false, // optional; default false
  "regionCode": "IN", // optional; default "IN"
  "units": "METRIC", // optional; "METRIC" | "IMPERIAL"; default "METRIC"
  "languageCode": "en", // optional; default "en"
}

Response 200

Array of route alternatives. See Route Schema for the Route object shape.

[
  { "distanceMeters": 425000, "routeLabels": ["DEFAULT_ROUTE"] /* ... */ },
  { "distanceMeters": 438000, "routeLabels": ["FUEL_EFFICIENT"] /* ... */ },
]

Errors

Status Code Condition
400 MISSING_FIELD origin or destination not provided
400 INVALID_FIELD Waypoint has neither location nor placeId; placeId < 6 chars
401 UNAUTHORIZED No valid Firebase ID token