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
Sets the content-type to entity.
Gets the content type of entity.
Sets the content ID of the entity.
Gets the content ID of entity.
Sets the content length of the entity.
Gets the content length of entity.
Sets the content disposition of the entity.
Gets the content disposition of entity.
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.
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.
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.
Extracts JSON body from the entity. If the entity body is not a JSON, an error is returned.
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.
Extracts xml
body from the entity. If the entity body is not an XML, an error is returned.
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.
Extracts text body from the entity. If the entity body is not text compatible an error is returned.
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.
Given an entity, gets the entity body as a byte[]
. If the entity size is considerably large consider
using getByteChannel() method instead.
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.
Given an entity, gets the entity body as a byte channel.
Given an entity, gets its body parts. If the entity body is not a set of body parts an error will be returned.
Given an entity, gets the body parts as a byte channel.
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.
Gets the header value associated with the given header name.
Gets all the header values associated with the given header name.
Gets all header names.
Adds the given header value against the given header.
Sets the given header value against the existing header. If a header already exists, its value is replaced with the given header value.
Removes the given header from the entity.
Removes all headers associated with the entity.
Checks whether the requested header key exists in the header map.
Sets the content-type to entity.
Parameters
- mediaType string
-
Content type that needs to be set to the entity
-
Return Type
(InvalidContentTypeError?) Nil if successful, error in case of invalid media-type
Gets the content type of entity.
-
Return Type
(string) Content type as a
string
Sets the content ID of the entity.
Parameters
- contentId string
-
Content ID that needs to be set to entity
Gets the content ID of entity.
-
Return Type
(string) Content ID as a
string
Sets the content length of the entity.
Parameters
- contentLength int
-
Content length that needs to be set to entity
Gets the content length of entity.
-
Return Type
(int | error) Content length as an
int
Sets the content disposition of the entity.
Parameters
- contentDisposition ContentDisposition
-
Content disposition that needs to be set to entity
Gets the content disposition of entity.
-
Return Type
(ContentDisposition) A
ContentDisposition
object
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
, orEntity[]
.
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.
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.
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. AnParserError
record is returned in case of errors.
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.
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. AnParserError
record is returned in case of errors.
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.
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 orParserError
in case of errors.
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.
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. AnParserError
record is returned in case of errors.
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
- byteChannel ReadableByteChannel
-
Byte channel 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.
Given an entity, gets the entity body as a byte channel.
-
Return Type
(ReadableByteChannel | ParserError) An
io:ReadableByteChannel
. AnParserError
record will be returned in case of errors
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. AnParserError
record will be returned in case of errors.
Given an entity, gets the body parts as a byte channel.
-
Return Type
(ReadableByteChannel | ParserError) Body parts as a byte channel
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.
Gets the header value associated with the given header name.
Parameters
- headerName string
-
Represents header name
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
-
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. UseEntity.hasHeader()
beforehand to check the existence of header.
Gets all the header values associated with the given header name.
Parameters
- headerName string
-
The header name
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
-
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. UseEntity.hasHeader()
beforehand to check the existence of header.
Gets all header names.
Parameters
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
-
Return Type
(string[]) All header names as a
string[]
Adds the given header value against the given header.
Parameters
- headerName string
-
The header name
- headerValue string
-
Represents the header value to be added
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
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
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
Removes the given header from the entity.
Parameters
- headerName string
-
Represents the header name
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
Removes all headers associated with the entity.
Parameters
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
Checks whether the requested header key exists in the header map.
Parameters
- headerName string
-
The header name
- position HeaderPosition (default LEADING)
-
Represents the position of the header as an optional parameter
-
Return Type
(boolean) True if the specified header key exists