Created a Folder calcfunction
and added the add_number
function:
def add_number(n1,n2):
sum = n1 + n2;
return sum;
print("The sum of two number is",sum)
Calling this method from Azure Function Python Class:
import logging
import azure.functions as func
from calcfunction import calc
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
id = req.params.get('id')
if not id:
try:
req_body = req.get_json()
except ValueError:
pass
else:
id = req_body.get('id')
if id:
return func.HttpResponse(f"This is the user entered userId {id} and calc function value {calc.add_number(12,24)}")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a ID in the query string or in the request body for a personalized response.",
status_code=200
)
My Azure Functions Project Folder Structure and the result:
