const classafBedSheet::Text

sys::Obj
  afBedSheet::Text

(Response Object) Use to send a text response to the client.

Text.fromHtml("<html>Hello!<html>")

This is purposely a concrete final class so there is no ambiguity as to what it is. For example, if a handler returned an Obj that was both a Text and a Redirect what is BedSheet supposed to do?

Best practice is to have your Entities implement a toText() or a toJson() method and return the result of that.

Text myHandler(MyEntity entity) {
  ...
  return entity.toJson
}

Note: prior to Fantom 1.0.66 the charset would always default to UTF-8 regardless of what Text is constructed with. See http://fantom.org/sidewalk/topic/2166#c13992.

contentType

Source

const MimeType contentType

fromContentType

Source

static new fromContentType(Str text, MimeType contentType)

Creates a Text with the given content type.

fromHtml

Source

static new fromHtml(Str html, Charset charset := Charset.utf8())

Creates a Text with the mime type text/html.

fromJson

Source

static new fromJson(Str json, Charset charset := Charset.utf8())

Creates a Text from the given Str with the mime type application/json.

fromJsonObj

Source

static new fromJsonObj(Obj jsonObj, Charset charset := Charset.utf8())

Creates a Text with the mime type application/json. jsonObj should be serialisable into Json via util::JsonOutStream

fromJsonObjP

Source

static new fromJsonObjP(Obj jsonObj, Str callbackFuncName, Charset charset := Charset.utf8())

Creates a Text with the mime type application/json. The json is wrapped in the given callback function name. jsonObj should be serialisable into Json via util::JsonOutStream.

fromJsonP

Source

static new fromJsonP(Str json, Str callbackFuncName, Charset charset := Charset.utf8())

Creates a Text with the mime type application/json. The json is wrapped in the given callback function name.

fromPlain

Source

static new fromPlain(Str text, Charset charset := Charset.utf8())

Creates a Text with the mime type text/plain.

fromXhtml

Source

static new fromXhtml(Str xhtml, Charset charset := Charset.utf8())

Creates a Text with the mime type application/xhtml+xml.

Be sure to give your XHTML an XML namespace:

<html xmlns="http://www.w3.org/1999/xhtml"> ... </html>

Or it will not be displayed correctly in the browser!

fromXml

Source

static new fromXml(Str xml, Charset charset := Charset.utf8())

Creates a Text with the mime type application/xml.

text

Source

const Str text

toStr

Source

virtual override Str toStr()