Sample APIS - using graph data structure and BFS (Breadth First Seach) algorithm
This application contains some sample APIS to create graph data structure and taversal through it using BFS (Breadth First Seach).
Prerequisite : Understanding of graph data structure and BFS
Here are details of APIs.
-
/host:
This API adds new host. Request Header : { "Content-type"" : "application/json" } Request Body: {"hostName":"A"}
-
/hosts:
This API returns list of all hots in array format.
-
/link :
This API adds new link. Request Header : { "Content-type"" : "application/json" } Request Body:
{"srcHost" : "A", "destHost" : "B","description" : "ftp"}
-
/links :
This API returns list of all links in array of objects format. Object has following properties: srcHost, destHost, description
-
/path/:srcHost/to/:destHost
This API returns the shortest path between srcHost and destHost. Response contains object with following properties:
- dataArr : Array containing all the hosts from srcHost to destHost in sequence. If no path exists between srcHost and destHost, this array is empty.
- overview : String containing route (destHost <--connectionMethod-- ...hosts ... --srcHost). If no path exists between srcHost and destHost, this string contains a suitable message. Here is sample response:
a) if path exists: { "hasError": false, "data": { "dataArr": [ "A", "D", "G", "I", "J", "L", "N", "R" ],
"overview": "R<--ftp--N<--rsync--L<--ftp--J<--ftp--I<--ftp--G<--ftp--D<--ftp--A" }
}
b) if path doesn't exist:
{ "hasError": false, "data": { "dataArr": [], "overview": "No Path exists between F and S" } }
-
Download this repo.
-
cd into this folder on your system terminal.
-
Run command "npm install"
-
Run command "node server.js"
-
Server starts on port 3000 by defulat. To use any of above api, append it to "http://localhost:3000". e.g. "http://localhost:3000/host".
-
Use any REST client to verify implementation. Please pass parameters as mentioned above.
-
Standard boilerplate for a nodejs server
-
Unified logging
-
Cron job to remove log file content everyday