Last active
April 4, 2017 08:38
-
-
Save elisedeux/4405d53ce05dbdc86963d060bd2ed5ea to your computer and use it in GitHub Desktop.
A query to find and display the shortest path between two nodes using Linkurious REST API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use the REST API to get the shortest path between two customers and render in Ogma | |
function shortestPath(customer1, customer2) { | |
// Configure and send the Ajax query asynchronously. | |
$.ajax({ | |
type: "GET", | |
// Define the authentication information. | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": "Basic " + btoa('root@root.com:6160b54b872459ce1c06c1a8ccdd9019') | |
}, | |
// REST method url | |
url: "http://localhost:3000/api/1cf9e65b/graph/shortestPaths", | |
// Message parameters | |
dataType: 'json', | |
data: { | |
startNode: `${customer1}`, | |
endNode: `${customer2}` | |
} | |
}).fail( () => { | |
// On error, display an alert. | |
alert( "Error" ); | |
}).done(data => { | |
// When the response arrives, update the graph. | |
updateGraph(data); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment