-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfunction_app.py
34 lines (27 loc) · 1.1 KB
/
function_app.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
34
import azure.functions as func
import logging
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.route(route="httpget", methods=["GET"])
def http_get(req: func.HttpRequest) -> func.HttpResponse:
name = req.params.get("name", "World")
logging.info(f"Processing GET request. Name: {name}")
return func.HttpResponse(f"Hello, {name}!")
@app.route(route="httppost", methods=["POST"])
def http_post(req: func.HttpRequest) -> func.HttpResponse:
try:
req_body = req.get_json()
name = req_body.get('name')
age = req_body.get('age')
logging.info(f"Processing POST request. Name: {name}")
if name and isinstance(name, str) and age and isinstance(age, int):
return func.HttpResponse(f"Hello, {name}! You are {age} years old!")
else:
return func.HttpResponse(
"Please provide both 'name' and 'age' in the request body.",
status_code=400
)
except ValueError:
return func.HttpResponse(
"Invalid JSON in request body",
status_code=400
)