# README
Go API client for openapi
With the GraphHopper Directions API you can integrate A-to-B route planning, turn-by-turn navigation, route optimization, isochrone calculations and other tools in your application.
The GraphHopper Directions API consists of the following RESTful web services:
- Routing API,
- Route Optimization API,
- Isochrone API,
- Map Matching API,
- Matrix API,
- Geocoding API and
- Cluster API.
Explore our APIs
Get started
Each API part has its own documentation. Jump to the desired API part and learn about the API through the given examples and tutorials.
In addition, for each API there are specific sample requests that you can send via Insomnia or Postman to see what the requests and responses look like.
Insomnia
To explore our APIs with Insomnia, follow these steps:
- Open Insomnia and Import our workspace.
- Specify your API key in your workspace: Manage Environments -> Base Environment ->
\"api_key\": your API key
- Start exploring
Postman
To explore our APIs with Postman, follow these steps:
- Import our request collections as well as our environment file.
- Specify your API key in your environment:
\"api_key\": your API key
- Start exploring
API Client Libraries
To speed up development and make coding easier, we offer the following client libraries:
- JavaScript client - try the live examples
- Others like C#, Ruby, PHP, Python, ... automatically created for the Route Optimization API
Bandwidth reduction
If you create your own client, make sure it supports http/2 and gzipped responses for best speed.
If you use the Matrix, the Route Optimization API or the Cluster API and want to solve large problems, we recommend you to reduce bandwidth
by compressing your POST request
and specifying the header as follows: Content-Encoding: gzip
. This will also avoid the HTTP 413 error "Request Entity Too Large".
Contact Us
If you have problems or questions, please read the following information:
To stay informed about the latest developments, you can
- follow us on twitter,
- read our blog,
- watch our documentation repository,
- sign up for our newsletter or
- our forum.
Select the channel you like the most.
Map Data and Routing Profiles
Currently, our main data source is OpenStreetMap. We also integrated other network data providers. This chapter gives an overview about the options you have.
OpenStreetMap
Geographical Coverage
OpenStreetMap covers the whole world. If you want to see for yourself if we can provide data suitable for your region, please visit GraphHopper Maps. You can edit and modify OpenStreetMap data if you find that important information is missing, e.g. a weight limit for a bridge. Here is a beginner's guide that shows how to add data. If you have edited data, we usually consider your data after 1 week at the latest.
Supported Vehicle Profiles
The Routing, Matrix and Route Optimization APIs support the following vehicle profiles:
Name | Description | Restrictions | Icon |
---|---|---|---|
car | Car mode | car access | ![]() |
small_truck | Small truck like a Mercedes Sprinter, Ford Transit or Iveco Daily | height=2.7m, width=2+0.4m, length=5.5m, weight=2080+1400 kg | ![]() |
truck | Truck like a MAN or Mercedes-Benz Actros | height=3.7m, width=2.6+0.5m, length=12m, weight=13000 + 13000 kg, hgv=yes, 3 Axes | ![]() |
scooter | Moped mode | Fast inner city, often used for food delivery, is able to ignore certain bollards, maximum speed of roughly 50km/h | ![]() |
foot | Pedestrian or walking without dangerous SAC-scales | foot access | ![]() |
hike | Pedestrian or walking with priority for more beautiful hiking tours and potentially a bit longer than foot . Walking duration is influenced by elevation differences. | foot access | ![]() |
bike | Trekking bike avoiding hills | bike access | ![]() |
mtb | Mountainbike | bike access | ![]() |
racingbike | Bike preferring roads | bike access | ![]() |
Please note:
- all motor vehicles (
car
,small_truck
,truck
andscooter
) support turn restrictions viaturn_costs=true
- the free package supports only the vehicle profiles
car
,bike
orfoot
- up to 2 different vehicle profiles can be used in a single optimization request. The number of vehicles is unaffected and depends on your subscription.
- we offer custom vehicle profiles with different properties, different speed profiles or different access options. To find out more about custom profiles, please contact us.
- a sophisticated
motorcycle
profile is available up on request. It is powered by the Kurviger Routing API and favors curves and slopes while avoiding cities and highways.
TomTom
If you want to include traffic, you can purchase the TomTom Add-on. This Add-on only uses TomTom's road network and historical traffic information. Live traffic is not yet considered. If you are interested to learn how we consider traffic information, we recommend that you read this article.
Please note the following:
- Currently we only offer this for our Route Optimization API.
- In addition to our terms, you need to accept TomTom's End User License Aggreement.
- We do not use TomTom's web services. We only use their data with our software.
Contact us for more details.
Geographical Coverage
We offer
- Europe including Russia
- North, Central and South America
- Saudi Arabia
- United Arab Emirates
- South Africa
- Australia
Supported Vehicle Profiles
Name | Description | Restrictions | Icon |
---|---|---|---|
car | Car mode | car access | ![]() |
small_truck | Small truck like a Mercedes Sprinter, Ford Transit or Iveco Daily | height=2.7m, width=2+0.4m, length=5.5m, weight=2080+1400 kg | ![]() |
Overview
This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.
- API version: 1.0.0
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.GoClientCodegen For more information, please visit https://www.graphhopper.com/
Installation
Install the following dependencies:
go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
Put the package under your project folder and add the following in import:
import sw "./openapi"
To use a proxy, set the environment variable HTTP_PROXY
:
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
Configuration of Server URL
Default configuration comes with Servers
field that contains server objects as defined in the OpenAPI specification.
Select Server Configuration
For using other server than the one defined on index 0 set context value sw.ContextServerIndex
of type int
.
ctx := context.WithValue(context.Background(), sw.ContextServerIndex, 1)
Templated Server URL
Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables
of type map[string]string
.
ctx := context.WithValue(context.Background(), sw.ContextServerVariables, map[string]string{
"basePath": "v2",
})
Note, enum values are always validated and all unused variables are silently ignored.
URLs Configuration per Operation
Each operation can use different server URL defined using OperationServers
map in the Configuration
.
An operation is uniquely identifield by "{classname}Service.{nickname}"
string.
Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices
and sw.ContextOperationServerVariables
context maps.
ctx := context.WithValue(context.Background(), sw.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), sw.ContextOperationServerVariables, map[string]map[string]string{
"{classname}Service.{nickname}": {
"port": "8443",
},
})
Documentation for API Endpoints
All URIs are relative to https://graphhopper.com/api/1
Class | Method | HTTP request | Description |
---|---|---|---|
ClusterAPIApi | AsyncClusteringProblem | Post /cluster/calculate | Batch Cluster Endpoint |
ClusterAPIApi | GetClusterSolution | Get /cluster/solution/{jobId} | GET Batch Solution Endpoint |
ClusterAPIApi | SolveClusteringProblem | Post /cluster | POST Cluster Endpoint |
GeocodingAPIApi | GetGeocode | Get /geocode | Geocoding Endpoint |
IsochroneAPIApi | GetIsochrone | Get /isochrone | Isochrone Endpoint |
MapMatchingAPIApi | PostGPX | Post /match | Map-match a GPX file |
MatrixAPIApi | CalculateMatrix | Post /matrix/calculate | Batch Matrix Endpoint |
MatrixAPIApi | GetMatrix | Get /matrix | GET Matrix Endpoint |
MatrixAPIApi | GetMatrixSolution | Get /matrix/solution/{jobId} | GET Batch Matrix Endpoint |
MatrixAPIApi | PostMatrix | Post /matrix | POST Matrix Endpoint |
RouteOptimizationAPIApi | AsyncVRP | Post /vrp/optimize | POST route optimization problem (batch mode) |
RouteOptimizationAPIApi | GetSolution | Get /vrp/solution/{jobId} | GET the solution (batch mode) |
RouteOptimizationAPIApi | SolveVRP | Post /vrp | POST route optimization problem |
RoutingAPIApi | GetRoute | Get /route | GET Route Endpoint |
RoutingAPIApi | PostRoute | Post /route | POST Route Endpoint |
RoutingAPIApi | RouteInfoGet | Get /route/info | Coverage information |
Documentation For Models
- Activity
- Address
- Algorithm
- BadRequest
- Cluster
- ClusterConfiguration
- ClusterConfigurationClustering
- ClusterConfigurationRouting
- ClusterCustomer
- ClusterCustomerAddress
- ClusterRequest
- ClusterResponse
- Configuration
- CostMatrix
- CostMatrixData
- CostMatrixDataInfo
- Detail
- DriveTimeBreak
- ErrorMessage
- GHError
- GHErrorHints
- GeocodingLocation
- GeocodingPoint
- GeocodingResponse
- GroupRelation
- InfoResponse
- InlineResponse404
- InternalErrorMessage
- IsochroneResponse
- IsochroneResponsePolygon
- IsochroneResponsePolygonProperties
- JobId
- JobRelation
- LineString
- MatrixRequest
- MatrixResponse
- MatrixResponseHints
- Objective
- Polygon
- Request
- Response
- ResponseAddress
- ResponseInfo
- Route
- RoutePoint
- RouteRequest
- RouteResponse
- RouteResponsePath
- RouteResponsePathInstructions
- Routing
- Service
- Shipment
- SnappedWaypoint
- Solution
- SolutionUnassigned
- Stop
- SymmetricalMatrixRequest
- TimeWindow
- TimeWindowBreak
- Vehicle
- VehicleProfileId
- VehicleType
Documentation For Authorization
api_key
- Type: API key
- API key parameter name: key
- Location: URL query string
Note, each API key must be added to a map of map[string]APIKey
where the key is: key and passed in as the auth context for each request.
Documentation for Utility Methods
Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:
PtrBool
PtrInt
PtrInt32
PtrInt64
PtrFloat
PtrFloat32
PtrFloat64
PtrString
PtrTime