There is an APi1(master) which will randomly select number 2 or 3. If it is 2 it should call api2 and if it is 3 it should call api3. API1 should not wait for the response from api2. It should call api3 immediately .Once after the specific task has been performed by api2 and api3 , they should respond to api1 stating that task has been performed by api2/api3 This is the below code I am trying with What I have tried: <pre>from flask import Flask, request from flask_restful import Api, Resource import requests import time app=Flask(__name__) api=Api(app) class Ms1(Resource): def get(): x=random.randint(1,3) if x==2: #need to call api2 class Ms2(Resource): #performing writing to a file task by api2 def get(self): L=["This is Hyderabad \n","Hello Hyderabad \n"] time.sleep(7) with open('readme.txt', 'w') as f: for line in lines: f.write(line) f.write('\n') #need to respond to api1 that task is completed class Ms3(Resource): #performing addition of 2 numbers using post task by api3 def post(self): postedData=request.get_json() num1=postedData["num1"] num2=postedData["num2"] res=num1+num2 retJson={ "status":200, "output"=res } return retJson api.add_resource(Ms1,"/ms1") api.add_resource(Ms2,"/ms2") api.add_resource(Ms3,"/ms3") if __name__=='__main__': app.run(debug=True)
Can we write the above 3 API's in a separate file and make a config.json file to include the urls so that each API runs on different server ? Anyone can provide me an idea on this ?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)