Skip to main content
All CollectionsOpen PlatformAPIAPI Courses
4.2 Case Studies of Server Deployment
4.2 Case Studies of Server Deployment

Introduce several case studies of server deployment.

Updated this week

What can You Learn in this Course?

  • Server deployment case (scheduled framework)

  • Server deployment case (front-end event)

  • Server deployment case (Webhook)


Course Content

Backend Application Case (Scheduled Framework)

import json
from apscheduler.schedulers.blocking import BlockingScheduler
import requestsdef get_jodoo_data():
    url = "https://www.jodoo.com/api/v1/app/5afe2461743ef87fde26a894/entry/5c12198c99b0d10dc49edfff/data"
    payload  = {}
    headers = {
      'Authorization': 'Bearer ????????????????????'
    }
    response = requests.request("POST", url, headers=headers, data = payload)
    print(response.text)
 
if __name__ == '__main__':
    scheduler = BlockingScheduler()
    scheduler.add_job(get_jodoo_data, 'cron', day_of_week='*' ,hour='14', minute='05', second='00')
    scheduler.start()

Backend Application Case (Front-End Event)

Type

Parameter

Data Format

Input parameter

x

JSON

Return parameter

y

JSON

from flask import Flask,request
import jsonapp = Flask(__name__)       def calc(x):
    y = x + 10
    return [email protected]('/test/' ,methods=['POST'])
def hello_world():
    x = json.loads(request.data)['x']
    y = calc(int(x))
    
    return json.dumps({'y':y})if __name__ == '__main__':
    app.run(host='0.0.0.0',port=3100)

Server Deployment Case (Webhook)

from flask import Flask,request
import json
import threadingapp = Flask(__name__)       def calc(x):
    y = x + 10
    print(y)@app.route('/test/' ,methods=['POST'])
def hello_world():
    x = json.loads(request.data)['data']['_widget_1586252392790']
    threading.Thread(target=calc,args=(int(x),)).start()
    return 'success',200if __name__ == '__main__':
    app.run(host='0.0.0.0',port=3100)


Assignments

1. Implement volume calculation (v=xyz) using the front-end event.

Hint: add four controls (x, y, z, v) to the form. After you enter x, y, and z (z is the field that triggers the event), the front-end event will be triggered to call the API. It will then calculate and write back to the v control.

2. Implement volume calculation (v=xyz) using Webhook.

Hint: Add four controls (x, y, z, v) to the form. After you enter x, y, and z and submit data, the Webhook will be triggered to push the data to ECS for volume calculation. After calculating v, use the data API to write the result back to the corresponding data.

from flask import Flask,request
import json
import threading
import requestsapp = Flask(__name__)       def post_to_jodoo(v,data_id):
    passdef calc(x,y,z,data_id):
    [email protected]('/test/' ,methods=['POST'])
def hello_world():
    x = json.loads(request.data)['data']['_widget_1586252719049']
    y = json.loads(request.data)['data']['_widget_1586252719064']
    z = json.loads(request.data)['data']['_widget_1586252719079']
    data_id = json.loads(request.data)['data']['_id']
    threading.Thread(target=calc,args=(float(x),float(y),float(z),data_id,)).start()
    return 'success',200if __name__ == '__main__':
    app.run(host='0.0.0.0',port=3100)

I have finished reading. 🏆

👉I can't wait to USE THE API.

👉I need more HELP in Discord Forum.

Did this answer your question?