AskYous
AskYous

Reputation: 4750

How do I get test data running functions locally?

I have the following:

export const helloWorld = functions.https.onRequest((request, response) => {
    response.send(request.body);
});

I ran it locally and ran helloWorld("Hey"), and this was the output:

firebase > helloWorld('HEY')
Sent request to function.
firebase > info: User function triggered, starting execution
info: Execution took 1 ms, user function completed successfully

RESPONSE RECEIVED FROM FUNCTION: 200, "{}"

Why does it only output {} when I clearly sent it a string?

Upvotes: 1

Views: 59

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317828

That's not how you invoke HTTP type functions locally. You should review the documentation and use the patterns established there. You invoke the method as if you were using the node request module:

For invoking HTTPS functions in the shell, usage is the same as the request NPM module, but replace request with the name of the function you want to emulate. For example:

# invoke
myHttpsFunction()
myHttpsFunction.get()
myHttpsFunction.post()

# invoke at sub-path
myHttpsFunction('/path')
myHttpsFunction.get('/path')
myHttpsFunction.post('/path')

# send POST request with form data
myHttpsFunction.post('/path').form( {foo: 'bar' })

I'm not sure you're able to specify the entire content body. That seems like an uncommon case, since you usually pass parameters to an HTTP function via its query string, or a form encoded body.

Upvotes: 2

Related Questions