02 - First Request
BRANCH: You can start from the branch
start
.
git checkout start
It is always good to split complex problem into multiple smaller ones. We will do the same thing with our assignment. So, let’s now focus only on the first request.
Triggering the first request
To get the response from our testing server we can use python library requests
.
-
Import the
requests
library.import requests
-
Get the response from our testing server.
@app.get("/api/smart") def smart_api_requester(): response = requests.get(BLOOMREACH_SERVER)
- Check the status code of the response.
@app.get("/api/smart") def smart_api_requester(): response = requests.get(BLOOMREACH_SERVER) if response.status_code == HTTPStatus.OK: pass
- Based on the status code, return a response from our endpoint.
@app.get("/api/smart") def smart_api_requester(): response = requests.get(BLOOMREACH_SERVER) if response.status_code == HTTPStatus.OK: return jsonify(success=True, response=response.json()) else: return jsonify(success=False)