parseRequestBody()function

parseRequestBody(request: Request, caller: AnyCaller = parseRequestBody): Promise<unknown>
ParamType
requestRequest
The Request whose body to parse. required
callerAnyCaller
Identity of the calling function for error attribution. Defaults to parseRequestBody
Return
Promise<unknown>
undefined If the request method is GET or HEAD (these request methods have no body).
unknown
unknown If content type is application/json and has valid JSON (including undefined if the content is empty).
unknown
unknown If content type is multipart/form-data then convert it to a simple Data object.
unknown
string If content type is text/plain or anything else (including "" empty string if it's empty).
Throws
RequestError
If the content is not text/plain, or application/json with valid JSON.

Parse the body content of an HTTP Request based on its content type, or throw RequestError if the content could not be parsed.

Examples

const body = await parseRequestBody(request);