The response object in CHAPI was created to give the programmer an easy way to handle everything about responding from its API endpoints.
By default, once an instance of Response is constructed, it comes with three attributes:
Current response body, defaulted to an empty string.
Current response status code (HTTP status), defaulted to 200.
Current response headers, defaulted to an empty array.
Here the function available:
Writes to the current response body, appends data.
Raw response data.
Sets the body for the current response, replaces contents (if any).
Raw response body.
Gets the status code for the current response.
An integer with the current response status code.
Sets the status code for the current response.
A valid HTTP response code (200, 404, 500, etc.).
Gets the current response body.
A string with the response body.
Sets the value of an specific header for the current response.
string with header name.
string with header value.
Gets the value of an specific header for the current response.
string with header name.
Header value or null if it's not set.
Sets all the headers for the current response.
Headers array.
Get the array of headers for the current response.
array with all current headers.
Does an HTTP redirection.
URL to redirect to.
Flushes headers and response body.
This function will always return true.
Flushes headers and response body.
string. Readable result for response (success or error are the most common).
array with data to respond.
string. Readable message for the response.
array. Extra information to pass that should be outside data
This function will always return true.
Flushes headers and response body.
string. Readable message for the response.
integer with HTTP code to respond, default to 404.
This function will always return true.
Shortcut / Helper function to respond a "bad HTTP method" error.
string. Bad method used.
This function will always return true.