HttpApiRequest

Hierarchy

  • HttpApiRequest

Properties

Optional Readonly body

body: string | FormData | ArrayBuffer

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:

  • 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

bodyType: "string" | "formdata" | "bytes"

Type of data stored in body.

Helps to understand what exactly is stored in the body property:

  • string: a simple string (type string).
  • formdata: data of a form ( type FormData).
  • bytes: binary data (type ArrayBuffer).

Optional Readonly fragment

fragment: undefined | string

Additional part of the URL path to the API method.

Optional Readonly headers

headers: Readonly<Record<string, string>>

Headers.

Readonly host

host: string

Domain or IP address of the request.

Optional Readonly method

method: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | string

HTTP request method.

Readonly path

path: string

Relative path to the URL API method.

Optional Readonly port

port: undefined | number

Request port.

Optional Readonly query

query: Readonly<URLSearchParams>

Parameters of the URL string for a query.

Readonly scheme

scheme: string

Request protocol.