coldbox.system.web.context

Class Response

lucee.Component
    extended by coldbox.system.web.context.Response

Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.ortussolutions.com HTTP Response model used mostly for RESTFul services, but it can be used as a nice way to represent responses in ColdBox

Class Attributes:
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
    Property Summary
    type property default serializable required
    boolean binary
          A binary indicator.

    • access = public
    • returntype = any
    false true false
    string contentType
          The content type of the response.

    • access = public
    • returntype = any
    true false
    any data
          The data struct that will be used to marshall out the response.

    • access = public
    • returntype = any
    true false
    boolean error
          A boolean error indicator.

    • access = public
    • returntype = any
    false true false
    string format
          The output format of the response, defaults to json.

    • access = public
    • returntype = any
    json true false
    array headers
          The headers to send with the response.

    • access = public
    • returntype = any
    true false
    string jsonCallback
          The json callback if any.

    • access = public
    • returntype = any
    true false
    string jsonQueryFormat
          JSON Only: This parameter can be a Boolean value that specifies how to serialize ColdFusion queries or a string with possible values row, column, or struct.

    • access = public
    • returntype = any
    true true false
    string location
          The location header if any.

    • access = public
    • returntype = any
    true false
    array messages
          An array of messages to output if any.

    • access = public
    • returntype = any
    true false
    struct pagination
          The pagination struct if any.

    • access = public
    • returntype = any
    true false
    numeric responsetime
          The response time.

    • access = public
    • returntype = any
    0 true false
    numeric statusCode
          The status code of the response.

    • access = public
    • returntype = any
    200 true false
    string statusText
          The status text of the response.

    • access = public
    • returntype = any
    OK true false
    Constructor Summary
    init()
          Constructor.
    Method Summary
    Response addHeader(string name, string value)
         Add a header into the response.
    Response addMessage(any message)
         Add some messages to the response.
    string getBinary()
    string getContentType()
    string getData()
    struct getDataPacket([boolean reset='false'])
         Returns a standard response formatted data packet using the information in the response.
    string getError()
    string getFormat()
    string getHeaders()
    string getJsonCallback()
    string getJsonQueryFormat()
    string getLocation()
    struct getMemento()
         Utility function to get the state of this object.
    string getMessages()
    string getMessagesString()
         Get all messages as a string.
    string getPagination()
    string getResponsetime()
    string getStatusCode()
    string getStatusText()
    any setBinary(boolean binary)
    any setContentType(string contentType)
    any setData(any data)
    Response setDataWithPagination([any data], [any resultsKey='results'], [any paginationKey='pagination'])
         Sets the data and pagination from a struct with a `results` and `pagination` key.
    any setError(boolean error)
    Response setErrorMessage(any errorMessage, [any statusCode], [any statusText=''])
         Sets the error message with a code for the API response.
    any setFormat(string format)
    any setHeaders(array headers)
    any setJsonCallback(string jsonCallback)
    any setJsonQueryFormat(string jsonQueryFormat)
    any setLocation(string location)
    any setMessages(array messages)
    Response setPagination([numeric offset='0'], [numeric maxRows='0'], [numeric page='1'], [numeric totalRecords='0'], [numeric totalPages='1'])
         Set the pagination data.
    any setResponsetime(numeric responsetime)
    Response setStatus(any code, [any text])
         Sets the status code with a statusText for the API response.
    any setStatusCode(numeric statusCode)
    any setStatusText(string statusText)
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init()

    Constructor


    Property Detail

    binary

    property boolean binary = [false]

    A binary indicator

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    contentType

    property string contentType

    The content type of the response

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    data

    property any data

    The data struct that will be used to marshall out the response

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    error

    property boolean error = [false]

    A boolean error indicator

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    format

    property string format = [json]

    The output format of the response, defaults to json

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    headers

    property array headers

    The headers to send with the response

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    jsonCallback

    property string jsonCallback

    The json callback if any

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    jsonQueryFormat

    property string jsonQueryFormat = [true]

    JSON Only: This parameter can be a Boolean value that specifies how to serialize ColdFusion queries or a string with possible values row, column, or struct

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    location

    property string location

    The location header if any

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    messages

    property array messages

    An array of messages to output if any

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    pagination

    property struct pagination

    The pagination struct if any

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    responsetime

    property numeric responsetime = [0]

    The response time

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    statusCode

    property numeric statusCode = [200]

    The status code of the response

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    statusText

    property string statusText = [OK]

    The status text of the response

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    addHeader

    public Response addHeader(string name, string value)

    Add a header into the response

    Parameters:
    name - The header name ( e.g. "Content-Type" )
    value - The header value ( e.g. "application/json" )

    addMessage

    public Response addMessage(any message)

    Add some messages to the response

    Parameters:
    message - Array or string of message to incorporate

    getBinary

    public string getBinary()


    getContentType

    public string getContentType()


    getData

    public string getData()


    getDataPacket

    public struct getDataPacket([boolean reset='false'])

    Returns a standard response formatted data packet using the information in the response

    Parameters:
    reset - Reset the 'data' element of the original data packet

    getError

    public string getError()


    getFormat

    public string getFormat()


    getHeaders

    public string getHeaders()


    getJsonCallback

    public string getJsonCallback()


    getJsonQueryFormat

    public string getJsonQueryFormat()


    getLocation

    public string getLocation()


    getMemento

    public struct getMemento()

    Utility function to get the state of this object


    getMessages

    public string getMessages()


    getMessagesString

    public string getMessagesString()

    Get all messages as a string


    getPagination

    public string getPagination()


    getResponsetime

    public string getResponsetime()


    getStatusCode

    public string getStatusCode()


    getStatusText

    public string getStatusText()


    setBinary

    public any setBinary(boolean binary)

    Parameters:
    binary

    setContentType

    public any setContentType(string contentType)

    Parameters:
    contentType

    setData

    public any setData(any data)

    Parameters:
    data

    setDataWithPagination

    public Response setDataWithPagination([any data], [any resultsKey='results'], [any paginationKey='pagination'])

    Sets the data and pagination from a struct with a `results` and `pagination` key.

    Parameters:
    data - The struct containing both 'results' and 'pagination' keys
    resultsKey - The name of the key with the results.
    paginationKey - The name of the key with the pagination.
    Returns:
    Returns the Response object for chaining

    setError

    public any setError(boolean error)

    Parameters:
    error

    setErrorMessage

    public Response setErrorMessage(any errorMessage, [any statusCode], [any statusText=''])

    Sets the error message with a code for the API response

    Parameters:
    errorMessage - The error message to set
    statusCode - The status code to set, if any
    statusText - The status text to set, if any
    Returns:
    Returns the Response object for chaining

    setFormat

    public any setFormat(string format)

    Parameters:
    format

    setHeaders

    public any setHeaders(array headers)

    Parameters:
    headers

    setJsonCallback

    public any setJsonCallback(string jsonCallback)

    Parameters:
    jsonCallback

    setJsonQueryFormat

    public any setJsonQueryFormat(string jsonQueryFormat)

    Parameters:
    jsonQueryFormat

    setLocation

    public any setLocation(string location)

    Parameters:
    location

    setMessages

    public any setMessages(array messages)

    Parameters:
    messages

    setPagination

    public Response setPagination([numeric offset='0'], [numeric maxRows='0'], [numeric page='1'], [numeric totalRecords='0'], [numeric totalPages='1'])

    Set the pagination data

    Parameters:
    offset - The offset
    maxRows - The max rows returned
    page - The page number
    totalRecords - The total records found
    totalPages - The total pages found

    setResponsetime

    public any setResponsetime(numeric responsetime)

    Parameters:
    responsetime

    setStatus

    public Response setStatus(any code, [any text])

    Sets the status code with a statusText for the API response

    Parameters:
    code - The status code to be set
    text - The status text to be set
    Returns:
    Returns the Response object for chaining

    setStatusCode

    public any setStatusCode(numeric statusCode)

    Parameters:
    statusCode

    setStatusText

    public any setStatusText(string statusText)

    Parameters:
    statusText