parseRequestBody()function
parseRequestBody(request: Request, caller: AnyCaller = parseRequestBody): Promise<unknown>
| Param | Type | |
|---|---|---|
request | Request | The Request whose body to parse. required |
caller | AnyCaller | Identity of the calling function for error attribution. Defaults to parseRequestBody |
| Return | |
|---|---|
Promise<unknown> | |
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);