0
votes

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"
        };
    }
};
1
I was able to get it to work by removing alpha in HTTP triggers route template. "project/{category:alpha}" to just "project/{category}". I was wondering what are the different types like alpha/int? - Mark

1 Answers

0
votes

alpha is a Route Constraint, it means Matches uppercase or lowercase Latin alphabet characters (a-z, A-Z). It's an optional option.

Now there is a limitation with the HttpTrigger and it does not support request with extensions (see this for details).

As stated in the issue, you can use proxies to workaround this limitation, but you do need to remove the alpha constraint from your route.