Oracle by Example brandingCreate a Python Application Using the Caching REST API

section 0Before You Begin

This tutorial shows you how to deploy a simple REST application in Python that implements the caching feature of Oracle Application Container Cloud Service. This tutorial takes approximately 10 to complete.

Background

Oracle Application Container Cloud Service lets you deploy Go, Java Platform, Standard Edition (Java SE), Node.js, PHP, Python, Ruby, and Enterprise Edition (Java EE) applications to Oracle Cloud.

The new caching capability of Oracle Application Container Cloud Service allows applications to accelerate access to data, share data among applications, and offload state management.

What Do You Need?

  • Access to an instance of Oracle Application Container Cloud Service (Make a note of your account information: identity domain, user name, and password.)
  • Python 3.6+
  • The pip package management system
  • Python Employee application project python-cache-app.zip
  • cURL 7.0+ with SSL support

section 1Create an Application Cache

  1. In a web browser, go to https://cloud.oracle.com/home and click Sign In.
  2. From the Cloud Account menu, select Traditional Cloud Account, select your data center, and click My Services.
  3. Enter your identity domain and click Go.
  4. Enter your cloud account credentials and click Sign In.
  5. In the Oracle Cloud My Services dashboard, click Action Action menu icon and select Oracle Application Container Cloud Service.
  6. Click Menu and select Application Cache.
  7. Click Create Service.
  8. In the Service Name field enter MyCacheApp, keep the default values, and then click Next:
    Create Application Cache page
    Description of the illustration cache_application.png
  9. In the Confirmation page, click Create.

section 2Prepare the Application for Cloud Deployment

  1. Extract the contents of the python-cache-app.zip file in your local system.
  2. Open a command-line window and go to the python-cache-app directory.
  3. Download the project dependencies.
    pip install -r requirements.txt -t modules 
  4. In the python-cache directory, create the manifest.json file and add the following content:
    {
      "runtime": {
        "majorVersion": "3.6.0"
      },
      "command": "sh ./start.sh",
      "isClustered": true,
      "release": {
        "version": "1.0"
      },
      "notes": "Python App using Cache REST API"
    } 
  5. Create the python-cache-app-dist.zip file with the content of the python-cache-app directory.

section 3Deploy the Application to Oracle Application Container Cloud

  1. Open the Oracle Application Container Cloud Service console.
  2. In the Applications list view, click Create Application.
  3. In the Create Application dialog box, click Python.
  4. In the Application section, enter EmployeeService for the name of your application. Click Browse next to Archive.
  5. In the File Upload dialog box, select python-cache-app-dist.zip and click Open.
  6. In the Application Cache field select MyCacheApp.
  7. Keep the default values in the Topology section and click Create. Processing takes a few minutes.
    Create Application dialog box
    Description of the illustration create_application.png
  8. When the application is created copy the URL.

section 4Testing the Application

  1. Open a command-line window (or a terminal in Linux).
  2. Put an employee object in cache. Replace the app_endpoint placeholder with the URL of your application.
    curl -i -X PUT -H "Content-Type:application/json" -d  "{\"id\":100,\"firstName\":\"Daniel\",\"lastName\":\"Branch\",\"email\":\"daniel.branch@example.com\",\"phone\":\"111111111\",\"birthDate\":\"1975-05-14\",\"title\":\"Developer Manager\",\"department\":\"IT\"}" app_endpoint/employees/100 
  3. Get the employee from cache.
    curl app_endpoint/employees/100 
  4. Remove the employee from cache.
    curl -i -X DELETE app_endpoint/employees/100 


more informationWant to Learn More?