【发布时间】:2023-01-04 11:38:27
【问题描述】:
我在 Azure 中有一个简单的函数应用程序,它以 JSON 格式返回数据。
https://myurl.com/api/symbolcountry/{id}?
它接受一个 id 作为参数。它运作良好。
但是我想参数化部分网址
https://myurl.com/api/{endpoint}/{id}?
我从来没有弄乱过 javascript 并且在试图弄清楚这个问题时有点发疯了。
函数.json 文件:
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
],
"route": "symbolcountry/{id}"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
index.js 文件:
module.exports = function (context, req) {
const method = req.method.toLowerCase();
var payload = null;
var entity = "";
switch(method) {
case "get":
if (req.params.id) {
entity = "symbolcountry"
payload = { "SymbolID": req.params.id};
}
else {
entity = "symbols"
}
break;
}
}
尝试在 function.json 中添加参数无济于事。
【问题讨论】:
标签: javascript azure-functions