Advertisement
MELAMOURI

Untitled

May 12th, 2023
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import azure.functions as func
  2. import datetime
  3. import logging
  4. def main(req: func.HttpRequest) -> func.HttpResponse:
  5.     logging.info('Python HTTP trigger function processed a request.')
  6.  
  7.     name = req.params.get('name')
  8.     id = req.params.get('id')
  9.  
  10.     if not name:
  11.         try:
  12.             req_body = req.get_json()
  13.         except ValueError:
  14.             pass
  15.         else:
  16.             name = req_body.get('name')
  17.  
  18.     if not id:
  19.         try:
  20.             req_body = req.get_json()
  21.         except ValueError:
  22.             pass
  23.         else:
  24.             id = req_body.get('id')
  25.  
  26.     if name and id:
  27.         current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  28.         response_message = f" my id is {id} and my name is {name} date :{current_time} "
  29.         return func.HttpResponse(response_message)
  30.     else:
  31.         return func.HttpResponse(
  32.              "Need query string",
  33.              status_code=400
  34.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement