-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_default_function_sample.py
33 lines (28 loc) · 1.11 KB
/
http_default_function_sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import azure.functions as func
import logging
app = func.FunctionApp()
@app.function_name(name="http_function_sample")
@app.route(route="req")
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info("Python HTTP-triggered function processed a request.")
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
"""
directly embedding user-controlled data like this (without escaping it) is only ok because the mimetype is `text/plain` by default
https://learn.microsoft.com/en-us/python/api/azure-functions/azure.functions.httpresponse?view=azure-python#parameters
"""
return func.HttpResponse(
f"Hello, {name}. This HTTP-triggered function executed successfully."
)
else:
return func.HttpResponse(
"This HTTP-triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)