VSCode Python Azure Functions 多参数示例
以下是一个用 Python 编写的多参数 Azure 函数示例:
import logging
import json
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
# 解析请求中的参数
name = req.params.get('name')
age = req.params.get('age')
email = req.params.get('email')
if not name or not age or not email:
return func.HttpResponse(
'Please pass name, age, and email on the query string',
status_code=400
)
# 构建响应
response = {
'name': name,
'age': age,
'email': email
}
return func.HttpResponse(
json.dumps(response),
mimetype='application/json'
)
这个函数接收三个参数:name、age 和 email,然后构建一个 JSON 响应包含这些参数的值。
你可以在请求 URL 中传递这些参数,如:http://localhost:7071/api/multi-params?name=John&age=25&email=john@example.com。
希望这个示例能对你有所帮助!
原文地址: https://www.cveoy.top/t/topic/oN8t 著作权归作者所有。请勿转载和采集!