In this section, you will clone the repository to your local machine and become familiar with the structure of the application. After that you will add two new simple API calls to your application.
- Log in to GitHub.
- Choose
username
-python-microservice from the Repositories menu on the left. - Click the green button Clone or download and copy the address starting with
[email protected]
. - Open Visual Studio Code and summon the Command Palette with
- Type
clone
and select Git: Clone from the list. - Paste the
[email protected]
address you copied before and provide the destination as required. - Open the newly cloned repository.
- Open the
username
-python-microservice repository in Visual Studio Code. - Open the
server/routes/index.py
file. - Read the
@app.route('/')
code block. - Go to http://username-python-microservice.mybluemix.net/ and observe the response.
- Read the
@app.route('/error404')
code block. - Go to http://username-python-microservice.mybluemix.net/error404 and observe the response.
- Open the
server/routes/health.py
file. - Read the
@app.route('/health')
code block. - Go to http://username-python-microservice.mybluemix.net/health and observe the response.
- Open the
server/routes/swagger.py
file. - Read the
@app.route('/swagger/api')
code block. - Go to http://username-python-microservice.mybluemix.net/swagger/api and observe the response.
- Read the
@app.route('/explorer')
code block. - Go to http://username-python-microservice.mybluemix.net/explorer and observe the response.
- Click the
/health
endpoint and the Try it out! button.
- Open the
username
-python-microservice repository in Visual Studio Code. - Open the
health.py
file. - Add the following code block and save the modifications.
@app.route('/answer') def answer(): answer = {'The Answer to Life the Universe and Everything': 42} return jsonify(answer)
- Open the Source Control panel in the left corner.
- Click the
+
icon next tohealth.py
to Stage Changes. - Write a meaningful commit message, such as
Created '/answer' endpoint
and click the√
icon. - On the bottom left corner, click the 🔄 icon to Synchronize Changes.
- Track the deployment progress in the Continuous Delivery Pipeline until the Deploy Stage passes.
- Go to http://username-python-microservice.mybluemix.net/answer and observe the response.
- Open the
username
-python-microservice repository in Visual Studio Code. - Open the
health.py
file. - Add the following code block to
health.py
and save the modifications.@app.route('/answer/<number>') def CheckAnswerToLifeTheUniverseAndEverything(number): content = { 'statement': 'The Answer to Life the Universe and Everything is ' + number + '.', 'check': 'The statement is ' + str(number == '42') + '!' } return jsonify(content)
- Open the Source Control panel in the left corner.
- Click the
+
icon next tohealth.py
to Stage Changes. - Write a meaningful commit message, such as
Created '/answer/<number>' endpoint
and click the√
icon. - On the bottom left corner, click the 🔄 icon to Synchronize Changes.
- Track the deployment progress in the Continuous Delivery Pipeline.
- Go to http://username-python-microservice.mybluemix.net/answer/42 and observe the response.
- Go to http://username-python-microservice.mybluemix.net/answer/24 and observe the response.