Develop a Cherrypy web service that exposes an API endpoint for calculating the shortest path between two nodes in a weighted graph, using Dijkstra's algorithm. PLAINFORMAT
import cherrypy
import json

class DijkstraWebService(object):
    @cherrypy.expose
    def shortest_path(self, graph, start, end):
        data = json.loads(graph)
        result = self.dijkstra(data, start, end)
        return json.dumps(result)

    def dijkstra(self, graph, start, end):
        shortest_paths = {start: (None, 0)}
        current_node = start
        visited = set()

        while current_node != end:
            visited.add(current_node)
            destinations = graph[current_node]
            weight_to_current_node = shortest_paths[current_node][1]

            for next_node, weight in destinations.items():
                weight += weight_to_current_node
                if next_node not in shortest_paths:
                    shortest_paths[next_node] = (current_node, weight)
                else:
                    current_shortest_weight = shortest_paths[next_node][1]
                    if current_shortest_weight > weight:
                        shortest_paths[next_node] = (current_node, weight)

            next_destinations = {
                node: short[1] for node, short in shortest_paths.items() if node not in visited}
            if not next_destinations:
                return "Route Not Possible"
            current_node = min(next_destinations, key=next_destinations.get)

        path = []
        while current_node is not None:
            path.append(current_node)
            next_node = shortest_paths[current_node][0]
            current_node = next_node
        path = path[::-1]
        return path


if __name__ == '__main__':
    cherrypy.quickstart(DijkstraWebService(), '/', {'global': {'server.socket_host': '0.0.0.0', 'server.socket_port': 8080}})