> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Osm Osrm

> LoT connector for the OSRM routing engine with no API key: routes, nearest road, duration matrices, GPS map matching and trip ordering

Technical Preview

## Overview

Client-mode REST API connectors for OpenStreetMap with no API key: Nominatim geocoding, reverse geocoding and OSM lookup, and OSRM routing, nearest road, duration matrix, GPS map matching and trip ordering, on the public servers or self-hosted.

This is one of the templates in the OpenStreetMap: Nominatim and OSRM (self-hostable) REST API app (`openstreetmap-nominatim-and-osrm`). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).

## Auth

* **schemes**: \["none"]
* **secrets**: \[]
* **note**: Nominatim usage policy: max 1 req/s, identifying User-Agent, no bulk geocoding, ODbL attribution

## Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Osm Osrm connector | no |
| `BaseUrl` | string | Osm Osrm base URL without trailing slash (e.g. [https://router.project-osrm.org](https://router.project-osrm.org)) | yes |

`BASE_ADDRESS` default: `https://router.project-osrm.org`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `OsrmRoute` | GET | `/route/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}` | `fleet/osm/osrm/route/get` | `fleet/osm/osrm/route/get/response` | `coordinates`, `params`, `profile` |
| `OsrmNearest` | GET | `/nearest/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}` | `fleet/osm/osrm/nearest/get` | `fleet/osm/osrm/nearest/get/response` | `coordinates`, `params`, `profile` |
| `OsrmTable` | GET | `/table/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}` | `fleet/osm/osrm/table/get` | `fleet/osm/osrm/table/get/response` | `coordinates`, `params`, `profile` |
| `OsrmMatch` | GET | `/match/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}` | `fleet/osm/osrm/match/get` | `fleet/osm/osrm/match/get/response` | `coordinates`, `params`, `profile` |
| `OsrmTrip` | GET | `/trip/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}` | `fleet/osm/osrm/trip/get` | `fleet/osm/osrm/trip/get/response` | `coordinates`, `params`, `profile` |

## Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-connectorCode OSM_OSRM"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR OsmOsrm WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://router.project-osrm.org"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT OsrmRoute
        WITH SOURCE_TOPIC "fleet/osm/osrm/route/get"
        WITH DESTINATION_TOPIC "fleet/osm/osrm/route/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/route/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
    ADD EVENT OsrmNearest
        WITH SOURCE_TOPIC "fleet/osm/osrm/nearest/get"
        WITH DESTINATION_TOPIC "fleet/osm/osrm/nearest/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/nearest/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
    ADD EVENT OsrmTable
        WITH SOURCE_TOPIC "fleet/osm/osrm/table/get"
        WITH DESTINATION_TOPIC "fleet/osm/osrm/table/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/table/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
    ADD EVENT OsrmMatch
        WITH SOURCE_TOPIC "fleet/osm/osrm/match/get"
        WITH DESTINATION_TOPIC "fleet/osm/osrm/match/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/match/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
    ADD EVENT OsrmTrip
        WITH SOURCE_TOPIC "fleet/osm/osrm/trip/get"
        WITH DESTINATION_TOPIC "fleet/osm/osrm/trip/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/trip/v1/{value.json.profile}/{value.json.coordinates}?generate_hints=false{value.json.params}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
```

Deploy it with `-addConnector` (do not include `ADD METADATA`).

## Usage example

Call `OsrmRoute` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'fleet/osm/osrm/route/get/response' &
mosquitto_pub -t 'fleet/osm/osrm/route/get' -m '{"coordinates": "<coordinates>", "params": "<params>", "profile": "<profile>"}'
```

## Related

* [REST API Connectors](https://docs.coreflux.org/v2.22/lot-language/routes/rest-api-routes.md)
* [REST API Apps catalog](https://docs.coreflux.org/v2.22/lot-language/routes/rest-api-apps.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.