Configure the Advanced I/O Function
The Advanced I/O function directory (functions/news_app_function) contains the following files:
- The main.py main function file
- The catalyst-config.json configuration file
- requirements.txt file
Add Code
You will be adding code in the main.py file.
The Advanced I/O function fetches the news item from its source table in the Data Store and forwards it to the client component as a JSON response.
Copy the code and paste it in the main.py in the functions/news_app_function directory.
import logging
from flask import Request, make_response, jsonify
import zcatalyst_sdk
def handler(request: Request):
#Initializing Catalyst SDK
app = zcatalyst_sdk.initialize()
logger = logging.getLogger()
# GET API that gets the news from the required table
if request.path == “/fetchData”:
table_name = request.args.get(“tablename”)
logger.info(“Fetching news from datastore table - “+table_name)
zcql_instance = app.zcql()
# Query to fetch news from table
query = “Select title,url from “+table_name
#Queries the Catalyst Data Store table and gets the required news
zcql_result = zcql_instance.execute_query(query)
return jsonify({“content”: zcql_result}), 200
else:
# For undefined path error will be thrown
response = make_response(‘Unknown path’)
response.status_code = 400
return response
The Advanced I/O function is now configured. We will discuss the application’s architecture after we configure the client.
Last Updated 2025-06-25 22:27:16 +0530 IST