From c0a87c7700450b50b03ec314cc4c0500da7cd032 Mon Sep 17 00:00:00 2001 From: David Eder Date: Mon, 7 Jun 2021 19:19:59 +0200 Subject: [PATCH] Add crossway api for cars --- components/x_way/x_way_server.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/components/x_way/x_way_server.py b/components/x_way/x_way_server.py index 76acd4a..b98b89d 100644 --- a/components/x_way/x_way_server.py +++ b/components/x_way/x_way_server.py @@ -1,17 +1,32 @@ +import requests +from bson import json_util from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app) +ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' + + @app.route('/') def hello_world(): return 'Hello World' -@app.route('/api1') -def api1(): - return 'api1' +@app.route('/api/v1/resources/cars', methods=['GET']) +def get_cars(): + + try: + response = requests.get(ENTITY_IDENT_URL + 'cars') + cars = response.json()['cursor'] + + except requests.exceptions.ConnectionError as e: + print("Is the entity_ident_server running and reachable?") + raise e + + return json_util.dumps({'cursor': cars}) + @app.route('/api2')