classafButter::Body

sys::Obj
  afButter::Body

Convenience methods for reading and writing content.

buf

Source

Buf? buf

Gets and sets the body content as a Buf.

charset

Source

Charset? charset

The charset used to en / decode the string and json objects. If left as null then it defaults to the Content-Type HTTP Header, or UTF-8 if not set.

charset should be set before the body content.

form

Source

[Str:Str]? form

Gets and sets the body content as a URL encoded form (think forms on web pages). Uri.encodeQuery() / Uri.decodeQuery() methods are used to convert objects to and from form values.

When set, the Content-Type is set to application/x-www-form-urlencoded (if it's not been set already).

Returns null if the body has not been set or if it's empty.

in

Source

InStream? in()

Returns the contents of the body as in InStream. Shortcut for buf?.seek(0)?.in.

json

Source

Str? json

Gets and sets the body content as a JSON string.

When set, the Content-Type is set to application/json (if it's not been set already).

Returns null if the body has not been set or if it is empty.

jsonList

Source

Obj?[]? jsonList

Gets and set the body content as a JSON list. Convenience for (Obj?[]?) body.jsonObj.

When set, the Content-Type is set to application/json (if it's not been set already).

Returns null if the body has not been set or if it's empty.

Note that JsonOutStream is used for the conversion. See the Json library should you need pretty printing or more control over conversion.

jsonMap

Source

[Str:Obj?]? jsonMap

Gets and set the body content as a JSON map. Convenience for ([Str:Obj?]?) body.jsonObj.

When set, the Content-Type is set to application/json (if it's not been set already).

Returns null if the body has not been set or if it's empty.

Note that JsonOutStream is used for the conversion. See the Json library should you need pretty printing or more control over conversion.

jsonObj

Source

Obj? jsonObj

Gets and sets the body content as a JSON object. JsonInStream / JsonOutStream are used to convert objects to and from JSON strings.

When set, the Content-Type is set to application/json (if it's not been set already).

Returns null if the body has not been set or if it's empty.

Note that JsonOutStream is used for the conversion. See the Json library should you need pretty printing or more control over conversion.

size

Source

Int size()

Returns the size of the body in bytes. Shortcut for buf?.size ?: 0.

str

Source

Str? str

Gets and sets the body content as a string. The string is en / decoded using a charset found in the following precedence:

  • any charset set via the charset field
  • the charset defined in a Content-Type HTTP header
  • UTF-8

When set, the Content-Type is set to text/plain (if it's not been set already).

Returns null if the body has not been set, and an empty Str if it's empty.