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"
};
}
};