Search code examples
node.jsazureazure-functionsurlparse

Parse URL in Azure functions


Am learning how to use Azure functions and so new to it. I have a httptrigger Azure function written in NodeJs. I am thinking of a logic on how to parse data from httptrigger function URL and use it in my code. Would like some suggestions on this?

In simple words,

  1. I would like to know how to pass a string parameter to the functions URL.
  2. Then parse the string from the URL and use it in my code logic.

Solution

  • See an example in Customize the HTTP endpoint.

    You can define route in function.json:

    "route": "products/{category:alpha}/{id:int?}"
    

    and then get URL parts from context:

    var category = context.bindingData.category;
    var id = context.bindingData.id;