The Response object use for building HTTP responses.
routes/my-route.php
As you see the code above, there are nothing related to response.
But behind the scene, the application will get the return value from route callback ("Hello!"
in this case)and pass it to the response object.
$this->response->setBody("Hello!")
By default, the response status code is 200
.
If you want to custom the response code, you can call $this->response->setStatusCode(403)
Or you can add a custom response header: $this->response->setHeader('header-name', 'foo')
By default, if the response body not a string. Array
or instance of Model
for example.
The response object will encode the response body to JSON data, and set the response content type to application/json