Routing Data Requests
curl --request POST \
--url https://www.usepathway.dev/api/routingimport requests
url = "https://www.usepathway.dev/api/routing"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://www.usepathway.dev/api/routing', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.usepathway.dev/api/routing",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.usepathway.dev/api/routing"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.usepathway.dev/api/routing")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.usepathway.dev/api/routing")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyEndpoint Examples
Routing Data Requests
This endpoint returns routing data requests.
POST
/
api
/
routing
Routing Data Requests
curl --request POST \
--url https://www.usepathway.dev/api/routingimport requests
url = "https://www.usepathway.dev/api/routing"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://www.usepathway.dev/api/routing', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.usepathway.dev/api/routing",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.usepathway.dev/api/routing"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.usepathway.dev/api/routing")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.usepathway.dev/api/routing")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyBody
POST Endpoint Usage
This documentation provides detailed instructions on using thePOST endpoint to submit routing data requests with our API.
Prerequisites
Ensure Node.js is installed and you have Axios and the filesystem module:npm install axios fs
const axios = require('axios');
const fs = require('fs'); // Import filesystem module for file handling
async function fetchRoute(coordinates) {
const apiKey = 'YOUR_API_KEY_HERE'; // Ensure you replace this with your actual API key
const apiUrl = 'https://www.usepathway.dev/api/routing';
const payload = {
data: {
coordinates: coordinates
}
};
try {
const response = await axios.post(apiUrl, payload, {
headers: {
'x-api-key': apiKey,
'Content-Type': 'application/json',
},
});
// Log and save detailed route information
console.log('Received Routing Data:', response.data);
response.data.routes.forEach((route, index) => {
const geometryData = `Route ${index + 1} Geometry:\n${route.geometry}\n`;
fs.writeFile(`route${index + 1}_geometry.txt`, geometryData, (err) => {
if (err) throw err;
console.log(`Geometry for Route ${index + 1 has been saved in a separate file.`);
});
});
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
}
}
// Sample coordinates for route calculation
const coordinates = [
[-122.4194, 37.7749], // San Francisco, CA
[-118.2437, 34.0522], // Los Angeles, CA
];
fetchRoute(coordinates);
JSON Response Structure
Here is an example of the JSON response structure after a successful POST request:{
"code": "Ok",
"routes": [
{
"geometry": "...",
"legs": [...],
"weight_name": "routability",
"weight": 633.6,
"duration": 630.7,
"distance": 4732.2
}
],
"waypoints": [
{
"hint": "...",
"distance": 4.231521214,
"name": "Friedrichstraße",
"location": [13.388798, 52.517033]
},
{
"hint": "...",
"distance": 2.795148358,
"name": "Torstraße",
"location": [13.39763, 52.529432]
}
]
}
⌘I