Doc inconsistencies around responses and basic function template

Further:

How do you use JSON sent to a function?

Do you read it from the body?

let body = JSON.parse(req.body);

No, that kills the function. (Also, in my testing, it kills it so hard that 9 of 10 console.log statements are not shown in the cli logs. Which, again, is problematic if you are use logging to debug problems.)

So what is req.body? Can I just output the value?

console.log(req.body);

Yields exactly nothing. A blank. Even if the body did actually have content.

So from here one would search something like “netlify function request body is always blank” and you would get a list of forum posts here that talk about a bug in the CLI or improperly formatted JSON. A lot of posts that lead you to believe there is something wrong outside of your function code.

But that’s wrong. Buried in one of those posts is:

And reading there, you finally find the answer:

req.json()

The answer refers to a Netlify blog post describing the change. Why isn’t this referring to the docs instead? Blog posts aren’t coming up in searches for dev issues.