Skip to content
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

Adding a first class HttpBinding + binding data support #568

Merged
merged 1 commit into from
Aug 15, 2016
Merged

Conversation

mathewc
Copy link
Member

@mathewc mathewc commented Aug 11, 2016

These changes are being made to address the following bugs:
#334 HttpTrigger: Request object needs to be part of bindingdata
#230 C#: Extract binding data for HttpTrigger

Currently for C# there is no binding data support for HttpTrigger, meaning you can't use binding expressions in your output bindings that reference data from the request. We were able to work around this limitation in Node (and the other script languages) because bindings for those languages are late bound meaning we can inject the binding data before the bind happens. For C# we can't, since binding contract validation is done when the function method is loaded into the host (same as in core SDK scenarios).

To address this, I'm introducing a minimal HttpTrigger binding. The behavior is:

  • for C#, to get any binding data support, the function must bind to a POCO (this is a core SDK requirement)
  • the public properties of the POCO then become available for binding expressions
  • at invoke time, if a request body is sent, the POCO and binding data will be populated from there
  • if no body is present, the POCO and binding data will be populated from query string parameters

Languages other than C# should continue to work the way they do now, except that they'll also now have the ability to bind to query string parameters (when no body is sent).

I'm not planning on checking this in until AFTER iteration 20 is complete.

"type": "blob",
"name": "outBlob",
"direction": "out",
"path": "samples-output/{Id}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't work before. Now you can bind to values from the payload.

Dictionary<string, object> bindingData = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
if (request.Content != null && request.Content.Headers.ContentLength > 0)
{
string body = request.Content.ReadAsStringAsync().Result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this method async (the caller is an async method as well) and await here to avoid .Result?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@fabiocav
Copy link
Member

fabiocav commented Aug 11, 2016

Took a quick first pass at this. Feels good to see this landing! :)
I'll take another look in the morning and address any questions you may have from the comments I made.

@mathewc mathewc force-pushed the http-binding branch 3 times, most recently from 7e4e1c3 to 67f54a7 Compare August 12, 2016 22:51
@mathewc
Copy link
Member Author

mathewc commented Aug 15, 2016

Merged. I'll address any additional feedback anyone has.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants