Object - mime : Entity

Represents the headers and body of a message. This can be used to represent both the entity of a top level message and an entity(body part) inside of a multipart entity.

Methods

setContentType

Sets the content-type to entity.

getContentType

Gets the content type of entity.

setContentId

Sets the content ID of the entity.

getContentId

Gets the content ID of entity.

setContentLength

Sets the content length of the entity.

getContentLength

Gets the content length of entity.

setContentDisposition

Sets the content disposition of the entity.

getContentDisposition

Gets the content disposition of entity.

setBody

Sets the body of the entity with the given content. Note that any string value is set as text/plain. To send a JSON-compatible string, set the content-type header to application/json or use the setJsonPayload method instead.

setFileAsEntityBody

Sets the entity body with a given file. This method overrides any existing content-type headers with the default content type application/octet-stream. The default value application/octet-stream can be overridden by passing the content type as an optional parameter.

setJson

Sets the entity body with the given json content. This method overrides any existing content-type headers with the default content type application/json. The default value application/json can be overridden by passing the content type as an optional parameter.

getJson

Extracts JSON body from the entity. If the entity body is not a JSON, an error is returned.

setXml

Sets the entity body with the given XML content. This method overrides any existing content-type headers with the default content-type application/xml. The default value application/xml can be overridden by passing the content-type as an optional parameter.

getXml

Extracts xml body from the entity. If the entity body is not an XML, an error is returned.

setText

Sets the entity body with the given text content. This method overrides any existing content-type headers with the default content-type text/plain. The default value text/plain can be overridden by passing the content type as an optional parameter.

getText

Extracts text body from the entity. If the entity body is not text compatible an error is returned.

setByteArray

Sets the entity body with the given byte[] content. This method overrides any existing content-type headers with the default content type application/octet-stream. The default value application/octet-stream can be overridden by passing the content type as an optional parameter.

getByteArray

Given an entity, gets the entity body as a byte[]. If the entity size is considerably large consider using getByteChannel() method instead.

setByteChannel

Sets the entity body with the given byte channel content. This method overrides any existing content-type headers with the default content-type application/octet-stream. The default value application/octet-stream can be overridden by passing the content-type as an optional parameter.

getByteChannel

Given an entity, gets the entity body as a byte channel.

getBodyParts

Given an entity, gets its body parts. If the entity body is not a set of body parts an error will be returned.

getBodyPartsAsChannel

Given an entity, gets the body parts as a byte channel.

setBodyParts

Sets body parts to entity. This method overrides any existing content-type headers with the default content type multipart/form-data. The default value multipart/form-data can be overridden by passing the content type as an optional parameter.

getHeader

Gets the header value associated with the given header name.

getHeaders

Gets all the header values associated with the given header name.

getHeaderNames

Gets all header names.

addHeader

Adds the given header value against the given header.

setHeader

Sets the given header value against the existing header. If a header already exists, its value is replaced with the given header value.

removeHeader

Removes the given header from the entity.

removeAllHeaders

Removes all headers associated with the entity.

hasHeader

Checks whether the requested header key exists in the header map.

setContentType

(string mediaType)

returns InvalidContentTypeError?

Sets the content-type to entity.

Parameters

  • mediaType string
  • Content type that needs to be set to the entity

getContentType

()

returns string

Gets the content type of entity.

  • Return Type

    (string)
  • Content type as a string

setContentId

Sets the content ID of the entity.

Parameters

  • contentId string
  • Content ID that needs to be set to entity

getContentId

()

returns string

Gets the content ID of entity.

  • Return Type

    (string)
  • Content ID as a string

setContentLength

Sets the content length of the entity.

Parameters

  • contentLength int
  • Content length that needs to be set to entity

getContentLength

()

returns int | error

Gets the content length of entity.

  • Return Type

    (int | error)
  • Content length as an int

setContentDisposition

Sets the content disposition of the entity.

Parameters

  • contentDisposition ContentDisposition
  • Content disposition that needs to be set to entity

getContentDisposition

()

returns ContentDisposition

Gets the content disposition of entity.

setBody

Sets the body of the entity with the given content. Note that any string value is set as text/plain. To send a JSON-compatible string, set the content-type header to application/json or use the setJsonPayload method instead.

Parameters

  • entityBody string | xml | json | byte | ReadableByteChannel | Entity[]
  • Entity body can be of the type string,xml,json,byte[],io:ReadableByteChannel, or Entity[].

setFileAsEntityBody

Sets the entity body with a given file. This method overrides any existing content-type headers with the default content type application/octet-stream. The default value application/octet-stream can be overridden by passing the content type as an optional parameter.

Parameters

  • filePath string
  • Represents the path to the file

  • contentType string (default application/octet-stream)
  • Content type to be used with the payload. This is an optional parameter. application/octet-stream is used as the default value.

setJson

Sets the entity body with the given json content. This method overrides any existing content-type headers with the default content type application/json. The default value application/json can be overridden by passing the content type as an optional parameter.

Parameters

  • jsonContent json
  • JSON content that needs to be set to entity

  • contentType string (default application/json)
  • Content type to be used with the payload. This is an optional parameter. application/json is used as the default value.

getJson

()

returns json | ParserError

Extracts JSON body from the entity. If the entity body is not a JSON, an error is returned.

  • Return Type

    (json | ParserError)
  • json data extracted from the the entity body. An ParserError record is returned in case of errors.

setXml

Sets the entity body with the given XML content. This method overrides any existing content-type headers with the default content-type application/xml. The default value application/xml can be overridden by passing the content-type as an optional parameter.

Parameters

  • xmlContent xml
  • XML content that needs to be set to entity

  • contentType string (default application/xml)
  • Content type to be used with the payload. This is an optional parameter. application/xml is used as the default value.

getXml

()

returns xml | ParserError

Extracts xml body from the entity. If the entity body is not an XML, an error is returned.

  • Return Type

    (xml | ParserError)
  • xml data extracted from the the entity body. An ParserError record is returned in case of errors.

setText

Sets the entity body with the given text content. This method overrides any existing content-type headers with the default content-type text/plain. The default value text/plain can be overridden by passing the content type as an optional parameter.

Parameters

  • textContent string
  • Text content that needs to be set to entity

  • contentType string (default text/plain)
  • Content type to be used with the payload. This is an optional parameter. text/plain is used as the default value.

getText

()

returns string | ParserError

Extracts text body from the entity. If the entity body is not text compatible an error is returned.

  • Return Type

    (string | ParserError)
  • string data extracted from the the entity body or ParserError in case of errors.

setByteArray

Sets the entity body with the given byte[] content. This method overrides any existing content-type headers with the default content type application/octet-stream. The default value application/octet-stream can be overridden by passing the content type as an optional parameter.

Parameters

  • blobContent byte
  • byte[] content that needs to be set to entity

  • contentType string (default application/octet-stream)
  • Content type to be used with the payload. This is an optional parameter. application/octet-stream is used as the default value.

getByteArray

()

returns byte | ParserError

Given an entity, gets the entity body as a byte[]. If the entity size is considerably large consider using getByteChannel() method instead.

  • Return Type

    (byte | ParserError)
  • byte[] data extracted from the the entity body. An ParserError record is returned in case of errors.

setByteChannel

Sets the entity body with the given byte channel content. This method overrides any existing content-type headers with the default content-type application/octet-stream. The default value application/octet-stream can be overridden by passing the content-type as an optional parameter.

Parameters

  • contentType string (default application/octet-stream)
  • Content-type to be used with the payload. This is an optional parameter. application/octet-stream is used as the default value.

getByteChannel

()

returns ReadableByteChannel | ParserError

Given an entity, gets the entity body as a byte channel.

getBodyParts

()

returns Entity[] | ParserError

Given an entity, gets its body parts. If the entity body is not a set of body parts an error will be returned.

  • Return Type

    (Entity[] | ParserError)
  • An array of body parts(Entity[]) extracted from the entity body. An ParserError record will be returned in case of errors.

getBodyPartsAsChannel

()

returns ReadableByteChannel | ParserError

Given an entity, gets the body parts as a byte channel.

setBodyParts

Sets body parts to entity. This method overrides any existing content-type headers with the default content type multipart/form-data. The default value multipart/form-data can be overridden by passing the content type as an optional parameter.

Parameters

  • bodyParts Entity[]
  • Represents the body parts that needs to be set to the entity

  • contentType string (default multipart/form-data)
  • Content-type to be used with the payload. This is an optional parameter. multipart/form-data is used as the default value.

getHeader

(string headerName)

returns string

Gets the header value associated with the given header name.

Parameters

  • headerName string
  • Represents header name

  • Return Type

    (string)
  • Header value associated with the given header name as a string. If multiple header values are present, then the first value is returned. An exception is thrown if no header is found. Use hasHeader() beforehand to check the existence of header.

getHeaders

(string headerName)

returns string

Gets all the header values associated with the given header name.

Parameters

  • headerName string
  • The header name

  • Return Type

    (string)
  • All the header values associated with the given header name as a string[]. An exception is thrown if no header is found. Use hasHeader() beforehand to check the existence of header.

getHeaderNames

()

returns string

Gets all header names.

  • Return Type

    (string)
  • All header names as a string[]

addHeader

Adds the given header value against the given header.

Parameters

  • headerName string
  • The header name

  • headerValue string
  • Represents the header value to be added

setHeader

Sets the given header value against the existing header. If a header already exists, its value is replaced with the given header value.

Parameters

  • headerName string
  • The header name

  • headerValue string
  • Represents the header value

removeHeader

Removes the given header from the entity.

Parameters

  • headerName string
  • Represents the header name

removeAllHeaders

Removes all headers associated with the entity.

hasHeader

(string headerName)

returns boolean

Checks whether the requested header key exists in the header map.

Parameters

  • headerName string
  • The header name

  • Return Type

    (boolean)
  • True if the specified header key exists