An THTTPRequest object is created by UB server and passed as the first argument to the endpoint's methods or as a second argument to the rest entity method's event.

It may be used to access HTTP request status, headers and data.

# new THTTPRequest ()

Members

# decodedParameters : string instance

URLDecoded parameters. Better to use req.parsedParameters instead, what returns an object

  
      // GET http://host:port/bla-bla?$filter=Name%20eq%20%27John%27
 req.parameters === '$filter=Name%20eq%20%27John%27'
 req.decodedParameters === "$filter=Name eq 'John'"
  

# decodedUri : string instance

The same as uri, but URLDecoded

  
      //GET http://host:port/ub/rest/TripPinServiceRW/My%20People"
req.decodedUri === 'TripPinServiceRW/My People'
  

# headers : string instance

HTTP request headers.

To get a single header value it is preferred to use req.getHeader(name) To get all parsed headers as object - req.getHeaders()

# method : string instance

HTTP request method GET|POST|PUT......

# parameters : string instance

URL parameters as string. Better to use req.parsedParameters instead, what returns an object

  
      // GET http://host:port/ub/rest/doc_document/report?id=1&param2=asdas
req.parameters === 'id=1&param2=asdas'
  

# parsedParameters instance

Return a parsed request parameters (decoded using querystring.parse()). Second call to parsedParameters uses cached result, so it faster than first

  
      // for parameters 'foo=bar&baz=qux&baz=quux&corge' return
req.parsedParameters // { foo: 'bar', baz: ['qux', 'quux'], corge: '' }
  

# requestId instance

Unique HTTP request ID - the same value as used to fill a uba_auditTrail.request_id. In case audit trail is disabled in domain (uba_auditTrail entity not available) or Ub server version < 5.18.2 returns 0

# uri : string instance

URL WITHOUT appName and endpoint name

  
      // GET http://host:port/ub/rest/doc_document/report?id=1&param2=asdas
req.uri === 'doc_document/report'
  

# url : string instance

Full URL

  
      // GET http://host:port/ub/rest/doc_document/report?id=1&param2=asdas
req.url === 'ub/rest/doc_document/report?id=1&param2=asdas'
  

Methods

# appendToFile (fullFilePathstring, encodingoptstring) → boolean instance

Append request body content (as binary) to a file. If file does not exist - creates it. Return true on success

Arguments:
  • fullFilePath: string
  • encoding = 'bin': string

    Can be 'bin'(default) or 'base64` - in this case request body will be converted from base64 into binary before write to file

# getHeader (namestring) → string | undefined instance

Return a header value by name. Name is case-insensitive

Arguments:
  • name: string

    Case-insensitive header name

  
      // incoming headers string 'Host: unitybase.info\r\nAccept-Encoding: gzip\r\n\r\nAccept-Encoding: deflate, br'
req.getHeader('accept-Encoding') // 'gzip, deflate, br
  

# getHeaderNames () → Array.<string> instance

Returns an array containing the unique names of the headers. All header names are lowercase

  
      // incoming headers string 'Host: unitybase.info\r\nAccept-Encoding: gzip\r\n\r\nAccept-Encoding: deflate, br'
req.getHeaderNames() // ['host', 'accept-encoding']
  

# getHeaders () instance

Return parsed headers object. Keys are lower-cased header names, values are header values

  
      // incoming headers string 'Host: unitybase.info\r\nAccept-Encoding: gzip\r\n\r\nAccept-Encoding: deflate, br'
req.getHeaders() // {host: "unitybase.info", accept-encoding: "gzip, deflate, br"}
  

# json () → * instance

Return http request body content as JSON; Faster when JSON.parse(req.read()).

Expect body to be in UTF8 encoding

# read (encodingoptString) → ArrayBuffer | String instance

Read from source

Return:

Return String in case no encoding passed or ArrayBuffer

Arguments:
  • encoding: String

    Optional encoding of source. Default to 'utf-8'. If 'bin' - return ArrayBuffer source representation without any conversion. If 'base64' - transform base64 encoded content of source to ArrayBuffer If 'bin2base64' - transform content to base64 encoded string

# writeToFile (fullFilePathstring, encodingoptstring) → boolean instance

Write request body content (as binary) to a file. Return true on success

Arguments:
  • fullFilePath: string
  • encoding = 'bin': string

    Can be 'bin'(default) or 'base64` - in this case request body will be converted from base64 into binary before write to file