Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import azure.functions as func
- import datetime
- def my_function(req: func.HttpRequest) -> func.HttpResponse:
- # Log the request processing
- log_message = 'Received HTTP request for name and id'
- logging.info(log_message)
- # Get the name and id parameters from the request
- name = req.params.get('name')
- id = req.params.get('id')
- # If the name or id is not present in the query params, check in the request body
- if not name:
- try:
- req_body = req.get_json()
- name = req_body.get('name')
- except ValueError:
- pass
- if not id:
- try:
- req_body = req.get_json()
- id = req_body.get('id')
- except ValueError:
- pass
- # If both name and id are present, construct the response message
- if name and id:
- current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- response_message = f"Hello {name}! Your ID is {id}. The current date and time is {current_time}."
- return func.HttpResponse(response_message)
- else:
- error_message = 'Invalid request: name and id are required parameters'
- logging.error(error_message)
- return func.HttpResponse(error_message, status_code=400)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement