cURL
curl --request POST \ --url https://www.usepathway.dev/api/routing
This endpoint returns routing data requests.
POST
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);
{ "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] } ] }