Body of the request.
The body property contains the data passed in the request body and can take different forms depending on the content type:
body
string
FormData
ArrayBuffer
// Handling formData if (!req.body) { return new HttpResponse(400) } if (req.bodyType === 'formdata') { const formData = <FormData>req.body; const fileData = <FormDataEntryFile | null>formData.get('file'); if (fileData) { const name = fileData.name; const arrayBuffer = await fileData.arrayBuffer(); const file = await System.files. createTemporary(name, arrayBuffer); } else { // Error: file not passed } } // Hnadling string if (req.bodyType === 'string') { if (req.headers['Content-Type'] === 'application/json') { const jsonBody = JSON.parse(req.body); // JSON object } else { const textBody = req.body; // Plain text } } // Handling ArrayBuffer if (req.bodyType === 'bytes') { const buffer = <ArrayBuffer>req.body; // Work with binary data }
Type of data stored in body.
Helps to understand what exactly is stored in the body property:
formdata
bytes
Additional part of the URL path to the API method.
Headers.
Domain or IP address of the request.
HTTP request method.
Relative path to the URL API method.
Request port.
Parameters of the URL string for a query.
Request protocol.
Your review is successfully sent!
Feedback sent successfully
Advanced request parameters
Hierarchy
Properties
Optional Readonly body
Body of the request.
The
bodyproperty contains the data passed in the request body and can take different forms depending on the content type:string— a string representation of the body, typically used for text or JSON requests;FormData— used when submitting form data, including files;ArrayBuffer— may be used for binary data, e.g., when sending raw files in binary format. Examples of handling:// Handling formData if (!req.body) { return new HttpResponse(400) } if (req.bodyType === 'formdata') { const formData = <FormData>req.body; const fileData = <FormDataEntryFile | null>formData.get('file'); if (fileData) { const name = fileData.name; const arrayBuffer = await fileData.arrayBuffer(); const file = await System.files. createTemporary(name, arrayBuffer); } else { // Error: file not passed } } // Hnadling string if (req.bodyType === 'string') { if (req.headers['Content-Type'] === 'application/json') { const jsonBody = JSON.parse(req.body); // JSON object } else { const textBody = req.body; // Plain text } } // Handling ArrayBuffer if (req.bodyType === 'bytes') { const buffer = <ArrayBuffer>req.body; // Work with binary data }Optional Readonly bodyType
Type of data stored in
body.Helps to understand what exactly is stored in the
bodyproperty:string: a simple string (typestring).formdata: data of a form ( typeFormData).bytes: binary data (typeArrayBuffer).Optional Readonly fragment
Additional part of the URL path to the API method.
Optional Readonly headers
Headers.
Readonly host
Domain or IP address of the request.
Optional Readonly method
HTTP request method.
Readonly path
Relative path to the URL API method.
Optional Readonly port
Request port.
Optional Readonly query
Parameters of the URL string for a query.
Readonly scheme
Request protocol.
Feedback sent successfully
Thank you for your input