I know that I can use query parameters in Azure functions to get the values
"myfunction?p=one&p2=two"
I am referring to this question
How can I do Routing in Azure Functions?
However it only addresses C# and node.js, I want to get the values following flask style
/function/<name>/<id>
which I can directly access, how do I do it in python in Azure functions
I also referred this doc, which only talks about node.js and C#
https://github.com/Azure/azure-functions-host/wiki/Http-Functions
You can add "route" to the function.json file to change the path, for example:
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post"
],
"route": "contact/{version}/certificate"
}
....
]
And in file __init__.py,
you can get version by version = req.route_params.get('version')
To be more dynamic like the path type of Python Flask route in azure functions you can customize the route to be like below. Main Concept is in the route's *{restOfPath}
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
],
"route": "Function1/{*restOfPath}"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
and edit the host.json to remove the word api from the URL like below.
{
"http": {
"routePrefix": ""
}
}
so with above configuration you can have the Function to serve URLs like below
Again to access it in init.py use it like below. You would get it as string
req.route_params.get("restOfPath")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With