Skip to content
Developer documentation

Restaurant-to-customer routing

Request a road route, read distance and duration, and decide what to do when the answer is degraded.

Restaurant-to-customer routing

Request a road route, read distance and duration, and decide what to do when the answer is degraded.

POST /v1/directions returns a road route between two points, with distance in metres and duration in seconds. The interesting engineering is not the happy path: it is what the service does when it cannot find an exact road route, and what your UI should do about it.

ts
const route = await fetch("https://api.bardiyamap.com/v1/directions", {
  method: "POST",
  headers: { "X-API-Key": key, "Content-Type": "application/json" },
  body: JSON.stringify({
    origin: { latitude: 30.0444, longitude: 31.2357 },
    destination: { latitude: 30.0626, longitude: 31.2497 },
    profile: "driving",
    geometries: "geojson",
    overview: "simplified",
  }),
}).then((response) => response.json());

const leg = route.routes?.[0];
console.log(leg.distance, leg.duration); // metres, seconds

Degraded routes

When no exact road path exists, the service does not fail the request: it returns a route marked degraded and tells you which part was substituted. The flags are part of the response contract.

FieldMeaning
degradedtrue when any part of the result was substituted
geometry_sourcewhere the drawn line came from: road network or a fallback
distance_sourcehow the distance was derived
ts
if (leg.degraded) {
  // Present it as an estimate, not as a commitment.
  ui.showEstimate({
    label: "Approximate route",
    reason: leg.distance_source,
    eta: Math.round(leg.duration / 60),
  });
} else {
  ui.showRoute({ eta: Math.round(leg.duration / 60) });
}

Strict road network mode

Send X-Strict-Road-Network: true when a substitute is worse than no answer, for example when computing a driver's payable distance. In strict mode the service refuses to snap to an approximate path and fails instead, so a degraded result never silently enters a settlement calculation.

shell
curl -X POST "https://api.bardiyamap.com/v1/directions" \
  -H "X-API-Key: $BARDIYA_API_KEY" \
  -H "X-Strict-Road-Network: true" \
  -H "Content-Type: application/json" \
  --data '{"origin":{"latitude":30.0444,"longitude":31.2357},"destination":{"latitude":30.0626,"longitude":31.2497}}'

Practical rules

  • Send geometries: "geojson" when you will draw the line; the default may be an encoded polyline your client cannot decode.
  • overview: "simplified" is enough for a thumbnail. Use a full geometry only when the client needs turn-level accuracy.
  • steps: true costs payload, not credits. Ask for it only when you render directions.
  • Waypoints keep their order. Each additional waypoint costs routing time, not an extra charge.
  • An unsupported profile is rejected, not silently downgraded to driving. Treat a 422 on profile as a configuration bug.