import os
import json
from flask import Flask
application = Flask(__name__)
port = int(os.environ.get('PORT', 8080))
@application.route('/')
def newtest():
return 'Hello World!'
@application.route('/test',methods=['GET'])
def myfunction():
data = [
{'Name': 'Deba', 'Id': 1,'Role':'Developer','Location':'Kolkata'},
{'Name': 'Kunal', 'Id': 2,'Role':'Support','Location':'Bengalore' },
{'Name': 'Shila', 'Id': 3,'Role':'Developer','Location':'Hyderabad'},
{'Name': 'Asish', 'Id': 4,'Role':'Tester','Location':'Bhubaneswar'},
{'Name': 'Umesh','Id': 5,'Role':'Architect','Location':'Pune'},
{'Name': 'Raja', 'Id': 6,'Role':'Support','Location':'Hyderabad'}
]
return data
if __name__ == '__main__':
application.debug = True
application.run(host='0.0.0.0', port=port)
Once the destination setup is done,now the next configuration is needed into the Fiori project structure in Business Application Studio.After creating a fiori application the destination that is defined into the connectivity section is important to mention into the xs-app.json file with source and target like below image.
As soon as the destination details has defined ,the next step is to build the logic to call the API using java-script file in the controller folder.
onBeforeRendering: function(){
this.callapi();
},
callapi:function(){
var that=this;
var settings = {
"url": this._getModulePath() +"/pythonapi"+"/test",
"method": "GET",
"timeout": 0,
};
$.ajax(settings).done(function (response) {
console.log(response);
that.getView().getModel("localData").setProperty("/api",response);
});
},
_getModulePath:function(){
var appId=this.getOwnerComponent().getManifestEntry("/sap.app/id");
var appPath=appId.replaceAll("." , "/");
var appModulePath=jQuery.sap.getModulePath(appPath);
return appModulePath;
}
<mvc:View controllerName="com.wipro.demfisample.controller.home1"
xmlns:mvc="sap.ui.core.mvc" displayBlock="true"
xmlns="sap.m"
xmlns:core="sap.ui.core"
>
<Page id="page" showHeader="false">
<content>
<Panel width="30%" class="panel">
<Label text="Fetched Data From API" design="Bold"/>
<List items="{path: 'localData>/api'}" >
<CustomListItem >
<HBox alignItems="Center" justifyContent="SpaceBetween" >
<VBox class="sapUiSmallMarginBegin sapUiSmallMarginTopBottom" >
<Text text="Name:{localData>Name}"/>
<Text text="Id:{localData>Id}"/>
<Text text="Role:{localData>Role}"/>
<Text text="Location:{localData>Location}"/>
</VBox>
</HBox>
</CustomListItem>
</List>
</Panel>
</content>
</Page>
</mvc:View>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 | |
3 |