Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Latest commit

 

History

History
75 lines (66 loc) · 4.15 KB

File metadata and controls

75 lines (66 loc) · 4.15 KB

Playing with your Python application

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.

Cloning the repository

  1. Log in to GitHub.
  2. Choose username-python-microservice from the Repositories menu on the left.
  3. Click the green button Clone or download and copy the address starting with [email protected].
  4. Open Visual Studio Code and summon the Command Palette with
  5. Type clone and select Git: Clone from the list.
  6. Paste the [email protected] address you copied before and provide the destination as required.
  7. Open the newly cloned repository.

Testing the example implementation

  1. Open the username-python-microservice repository in Visual Studio Code.
  2. Open the server/routes/index.py file.
  3. Read the @app.route('/') code block.
  4. Go to http://username-python-microservice.mybluemix.net/ and observe the response. congratulations
  5. Read the @app.route('/error404') code block.
  6. Go to http://username-python-microservice.mybluemix.net/error404 and observe the response.
  7. Open the server/routes/health.py file.
  8. Read the @app.route('/health') code block.
  9. Go to http://username-python-microservice.mybluemix.net/health and observe the response.
  10. Open the server/routes/swagger.py file.
  11. Read the @app.route('/swagger/api') code block.
  12. Go to http://username-python-microservice.mybluemix.net/swagger/api and observe the response.
  13. Read the @app.route('/explorer') code block.
  14. Go to http://username-python-microservice.mybluemix.net/explorer and observe the response.
  15. Click the /health endpoint and the Try it out! button.

Customizing the example implementation

  1. Open the username-python-microservice repository in Visual Studio Code.
  2. Open the health.py file.
  3. 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)
  4. Open the Source Control panel in the left corner.
  5. Click the + icon next to health.py to Stage Changes.
  6. Write a meaningful commit message, such as Created '/answer' endpoint and click the icon.
  7. On the bottom left corner, click the 🔄 icon to Synchronize Changes.
  8. Track the deployment progress in the Continuous Delivery Pipeline until the Deploy Stage passes.
  9. Go to http://username-python-microservice.mybluemix.net/answer and observe the response.

Customizing the example implementation again

  1. Open the username-python-microservice repository in Visual Studio Code.
  2. Open the health.py file.
  3. 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)
  4. Open the Source Control panel in the left corner.
  5. Click the + icon next to health.py to Stage Changes.
  6. Write a meaningful commit message, such as Created '/answer/<number>' endpoint and click the icon.
  7. On the bottom left corner, click the 🔄 icon to Synchronize Changes.
  8. Track the deployment progress in the Continuous Delivery Pipeline.
  9. Go to http://username-python-microservice.mybluemix.net/answer/42 and observe the response.
  10. Go to http://username-python-microservice.mybluemix.net/answer/24 and observe the response.