I have an Azure Function with route as "project/{category}" which SQLs to my Cosmos DB. So my function.json has
"sqlQuery": "SELECT * from c where c.category = {category}"
Everything is fine when the HTTP endpoint parameter for category has no space like "http://.azurewebsites.net/api/project/rainbow" or "http://.azurewebsites.net/api/project/nospace". It is able to SQL category = rainbow or category = nospace.
But when I have an HTTP endpoint parameter like "http://.azurewebsites.net/api/project/rain%20bow" or "http://.azurewebsites.net/api/project/yes%20space". It does not show anything.
How do I handle parameters to be used in my javascript Azure Function? Replace %20 of context.bindingData.category to actual spaces " ", then run the sqlQuery.
Here is my code
module.exports = async function (context, req) {
if (context.bindingData.category) {
context.res = {
status: 200, /* Defaults to 200 */
body: context.bindings.inputDocument,
headers: {
'Content-Type': 'application/json'
}
};
}
else {
context.res = {
status: 400,
body: "Error"
};
}
};
答案 0 :(得分:0)
alpha
是Route Constraint,表示Matches uppercase or lowercase Latin alphabet characters (a-z, A-Z)
。这是一个可选选项。
现在HttpTrigger有一个限制,它不支持带有扩展名的请求(有关详细信息,请参见this)。
如问题中所述,您可以使用代理来解决此限制,但是您确实需要从路线中删除alpha
约束。