RESTfulAPI::answer PHP Method

answer() public method

Output the API response to client then exit.
public answer ( string $json = null, boolean $corsPreflight = false )
$json string Response body
$corsPreflight boolean Set to true if this is a XHR preflight request answer. CORS shoud be enabled.
    public function answer($json = null, $corsPreflight = false)
    {
        $answer = new SS_HTTPResponse();
        //set response body
        if (!$corsPreflight) {
            $answer->setBody($json);
        }
        //set CORS if needed
        $answer = $this->setAnswerCORS($answer);
        $answer->addHeader('Content-Type', $this->serializer->getcontentType());
        // save controller's response then return/output
        $this->response = $answer;
        return $answer;
    }