-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support binding query parameters in HttpTriggers (C#) #7610
Comments
Hi @Sti2nd , Thank you for your feedback! We will check for the possibilities internally and update you with the findings. |
Hi @Sti2nd , To use query parameter, if the query is coming from a query string then you can use query.id instead of id. Where id is the query string name. { |
Sorry, I don't understand where this JSON is coming from? Developing Azure Functions in Visual Studio there are no JSON. |
Hi @Sti2nd , Here is how you can Add bindings to Azure Functions in visual studio - https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs#add-bindings Here is how you can add the bindings in C# language - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-example#c-script-example As of today, Query parameters can be passed using Query.id Here is one more example - https://docs.microsoft.com/en-us/azure/azure-functions/functions-add-output-binding-storage-queue-vs |
Thank you @v-anvari , public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "users/{id}")] HttpRequest req,
string id,
[FromQuery] string name)
{ Notice the |
Thank you for your feedback! We will investigate this further and update as appropriate |
Hi @Sti2nd, Transferring this issue to function host for further investigation. |
Not sure if following information is helpful to @Sti2nd but for anyone reaching here due to a "Binding not supported" exception when using Being used to that syntax from ASP.Net Web APIs, my expectation was that this is by default supported by Azure Functions as well (HTTP-Trigger based functions). After some googling, I was about to loose all hope because all references (at least those that I found) state that it is either not possible or they simply expect you to either use route configuration or fetch the query parameter from the request object or instead of using GET use a POST request and pass what you want to be passed as part of the request body... Since all of that was not really satisfying, I was about to implement my own custom BindingProvider for the POCO objects I wanted to use in my GET requests to the function... Then I had a closer look at the source of azure-webjobs-sdk-extensions and found this: HttpDirectRequestBindingProvider From the comment on that class:
Order of course matters only in that sense, that your Poco object needs to be decorated with the
And the paginationFilter is properly filled with provided (or default values) values when calling the endpoint like
Note: The usage of Also see my answer to a related issue on StackOverflow |
Thanks @TobiasBreuer, thats a great example on how data passed to the functions should be handled. I am trying to wrap a different query parameter name like value_id to ValueId, but i can't seem to get it working. I tried [FromQuery(Name = "value_id")] and also DataMember, but nothing seems to work. Do you have a solution for this too? :-) |
Hi @MO2k4, when given as QueryString parameter, for GET requests I don't know of any build-in functionality to perform such a mapping when the names differ. Depending on the type of request your are performing I see two options: In case it is a GET, you'll have to either use the Route parameter or access the query parameter the classic way like In case it is a POST, and
Hope this helps 😉 |
I've opened in pr for this 😅 PR 787 |
The HttpTrigger already supports binding route parameters to variables in C# and it would be nice if it supported binding query parameters as well.
Related info: ASP.NET Core supports binding query parameters using the FromQuery attribute
UserVoice link. Probably isn't needed since Microsoft will stop using UserVoice.
The text was updated successfully, but these errors were encountered: