I’m experimenting with Netlify Functions, I’m trying to do an API call through a Netlify Function by submitting a form. But how do I do this?
The function is working as expected, but I’m unable to pass data to the function to use in the API call.
Also, how can this, if the function is receiving data?
I’ll try again, I know how the fetching/posting data works in JavaScript, so JavaScript itself isn’t the problem for this.
Receiving data through the request ok, but how can I test this during development? Since it’s server sided, it won’t log in the browser’s console or I can’t debug in the frontend.
@nathanmartin there’s the problem. I know how to run/execute a function and indeed I can see the log then, but I don’t see any logging when I call the function from the frontend. Then there’s no logging…
@andylemaire Then you want what I posted in the message prior.
In all cases you won’t see the logs from your functions in the browser console because your functions aren’t executing in the browser.
You will see them where the function is running, so either in your terminal when you’re running the simulated function via the Netlify CLI, or in the Netlify proffered logs when executing in the cloud.
@andylemaire, Netlify docs cover most of what you’ve asked (if not, let us know and we can fix it). But the new API basically uses the Web Standard Reuest object: Request - Web APIs | MDN (mozilla.org), so accessing the body should be req.body or even req.json() (there are more methods, please refer to the MDN docs).
When you say “not the correct value”, you might be getting a stream as request bodies are a stream by default.