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

Output bindings not registered #4335

Closed
JamieMagee opened this issue Apr 19, 2019 · 3 comments
Closed

Output bindings not registered #4335

JamieMagee opened this issue Apr 19, 2019 · 3 comments
Assignees

Comments

@JamieMagee
Copy link

JamieMagee commented Apr 19, 2019

I'm unable to get any output bindings to work when debugging locally using Azure Functions core tools. That includes using the example functions

Investigative information

n/a (Debugging locally)

Repro steps

Debug the function attached at the bottom of the bug report. context.bindings only contains 1 binding, but it should include 2: An input and an output. Both bindings are correctly defined in context.bindingDefinitions.

Trigger using curl localhost:7071/api/HttpTrigger

Related information

Environment
  • Arch Linux
  • Azure Functions core tools: 2.5.553
Source
{
  "bindings": [
    {
      "name": "req",
      "type": "httpTrigger",
      "direction": "in"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}
import { AzureFunction, Context } from '@azure/functions';

const index: AzureFunction = async function (context: Context): Promise<void> {
    
};

export default index;
@pragnagopa
Copy link
Member

@JamieMagee - generated function.json looks right. Can you please explain what do you mean by

unable to get any output bindings to work

cc @mhoeger for follow up

@mhoeger
Copy link
Contributor

mhoeger commented Apr 29, 2019

@JamieMagee - I think what you're referring to is that the "bindings" object only contains the names and values of input / trigger type bindings. This is expected behavior as we've documented it (in our docs and in our TypeScript type definitions).

We do also say to set output through context.bindings (more info here), you can do it as follows:

import { AzureFunction, Context } from '@azure/functions';

const index: AzureFunction = async function (context: Context): Promise<void> {
    context.log('res' in context.bindings); // logs "false"
    context.log(context.bindings.res); // logs "undefined"
    context.bindings.res = {
        body: "hello, world",
        status: 200
    }
};

export default index;

Is the ask to change it so that the output binding key name is there with a starting value of "undefined"? So when you inspect the context object, you see that output bindings should be assigned to?

Another thing to note is that on context, there is a special http response object, "res", that sets http output in a way that is different from any other output binding type. If you look at the context.res object, you'll see it's already defined and has a few methods on it. This is to allow users to do "express-like" calls like context.res.send("hello world!"); (more here). Notice that it is scoped under "context" instead of "context.bindings", because it is treated as separate from the other dynamically generated output bindings (example of blob output).

Admittedly.... it is very confusing and not very intuitively organized.

Although we can't make a change in V2, can you tell us what your expectations were when you were trying to create an HTTP response? This is something we can improve in future major versions!

@ahmedelnably
Copy link

Closing as resolved

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

No branches or pull requests

4 participants