API Usage
The API server allows you to interact with the application via HTTP GET requests. This enables you to calculate paths, compare algorithms, and manage settings programmatically.
Starting the API Server
Once you run the macLinuxProjectBuilder.sh or windowsProjectBuilder.bat script, the API server starts automatically. The terminal will display a message similar to this:
API server running on port <port>
Try the longest path -> http://localhost:<port>/path?start=9588784&end=2720178This confirms that the server is ready to accept requests. The default port is set in the application but can be modified using the CLI command port.
API Endpoints
The following endpoints are available for interacting with the server:
Basic Shortest Path
Endpoint:
/pathDescription: Calculates the shortest path between two nodes using A*.
Parameters:
start(integer): The starting node.end(integer): The ending node.format(optional): Response format (jsonorxml).
Example:
GET http://localhost:<port>/path?start=1&end=5Response (JSON):
{ "path": [1, 3, 5], "distance": 12.5 }
Debug Path
Endpoint:
/debug_pathDescription: Provides detailed information about the calculated path, including heuristic weight, computation time, and more.
Parameters: Same as
/path.Example:
Response (JSON):
Comparator Path
Endpoint:
/comp_pathDescription: Compares the shortest paths calculated by A* and Dijkstra algorithms.
Parameters: Same as
/path.Example:
Response (JSON):
Command Endpoint
Endpoint:
/cmdDescription: Sends a command to the application via the API.
Parameters:
command(string): The CLI command to execute.format(optional): Response format (jsonorxml).
Example:
Response Formats
You can request responses in either JSON or XML by appending the format parameter to the query string:
JSON (default):
XML:
Stopping the API Server
The API server stops when you exit the CLI. To stop the application:
Type
exitin the terminal.
Last updated