Skip to content

Commit 4b040b9

Browse files
committed
Documentation
1 parent efa843a commit 4b040b9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,37 @@ In both `PUT` and `POST` cases, if neither JSON nor form content are specified,
206206
the raw string of the body will be returned.
207207

208208
## Response Object
209+
210+
The response object allows for granular control over the HTTP response sent back
211+
to the browser.
212+
213+
### Methods
214+
215+
#### `setHeader($k, $v)`
216+
217+
Allows you to set or override default headers before the response is sent.
218+
219+
```php
220+
$res->setHeader('Content-Type', 'application/json');
221+
$res->send(json_encode(array('foo' => 'bar')));
222+
```
223+
224+
NOTE: the default content type of responses will be `text/html`.
225+
226+
#### `setHeaders($headers)`
227+
228+
Shortcut to set multiple headers at once. This method accepts an array of headers
229+
where the key is the header name and the value is the header content.
230+
231+
#### `send($content, [$code])`
232+
233+
This method will send the final built response back to the user. The optional
234+
`$code` parameter will allow you to specify status codes other than the default
235+
`200 Success` response.
236+
237+
```php
238+
$router->route('*', '/admin', function ($req, $res) {
239+
$res->send('What do you think you are doing?', 500);
240+
});
241+
```
242+

0 commit comments

Comments
 (0)