You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add details about req.body
* improve a bit how it looks
* improve a bit more
* Update components/references-mdx/runtimes/official-runtimes/official-runtimes.mdx
* Update components/references-mdx/runtimes/official-runtimes/official-runtimes.mdx
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Shu Uesugi <[email protected]>
Copy file name to clipboardExpand all lines: components/references-mdx/runtimes/official-runtimes/official-runtimes.mdx
+40-8
Original file line number
Diff line number
Diff line change
@@ -148,14 +148,14 @@ Each request to a Node.js Serverless Function gives access to Request and Respon
148
148
149
149
​<ProductName /> additionally provides helper methods inside of the Request and Response objects passed to Node.js Serverless Functions. These methods are:
|`req.query`| An object containing the request's [query string](https://en.wikipedia.org/wiki/Query_string), or `{}` if the request does not have a query string. | Request |
154
-
|`req.cookies`| An object containing the cookies sent by the request, or `{}` if the request contains no cookies. | Request |
155
-
|`req.body`| An object containing the body sent by the request, or `null` if no body is sent. | Request |
156
-
|`res.status(code)`| A function to set the status code sent with the response where `code` must be a valid [HTTP status code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes). Returns `res` for chaining. | Response |
157
-
|`res.send(body)`| A function to set the content of the response where `body` can be a `string`, an `object` or a `Buffer`. | Response |
158
-
|`res.json(obj)`| A function to send a JSON response where `obj` is the JSON object to send. | Response |
|`req.query`| An object containing the request's [query string](https://en.wikipedia.org/wiki/Query_string), or `{}` if the request does not have a query string. | Request |
154
+
|`req.cookies`| An object containing the cookies sent by the request, or `{}` if the request contains no cookies. | Request |
155
+
|[`req.body`](#official-runtimes/node-js/node-js-request-and-response-objects/request-body)| An object containing the body sent by the request, or `null` if no body is sent. | Request |
156
+
|`res.status(code)`| A function to set the status code sent with the response where `code` must be a valid [HTTP status code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes). Returns `res` for chaining. | Response |
157
+
|`res.send(body)`| A function to set the content of the response where `body` can be a `string`, an `object` or a `Buffer`. | Response |
158
+
|`res.json(obj)`| A function to send a JSON response where `obj` is the JSON object to send. | Response |
159
159
160
160
The following Node.js Serverless Function example showcases the use of `req.query`, `req.cookies` and `req.body` helpers:
161
161
@@ -207,6 +207,38 @@ We follow a set of rules on the `Content-type` header sent by the request to do
207
207
208
208
With the `req.body` helper, you can build applications without extra dependencies or having to [parse the content of the request manually](https://nodejs.org/ja/docs/guides/anatomy-of-an-http-transaction/#request-body).
209
209
210
+
<Note>
211
+
The <InlineCode>req.body</InlineCode> helper is set using a{''}
. In turn, it is only computed when it is accessed.
219
+
</Note>
220
+
221
+
When the request body contains malformed JSON, accessing `req.body` will throw an error. You can catch that error by wrapping `req.body` with [`try...catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch):
0 commit comments