Skip to content

Commit 0ff05cf

Browse files
committed
feat: add custom response documentation
1 parent 3713b9e commit 0ff05cf

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/docs/http/response.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ Plain text responses can be created using the `plain()` method. This method acce
6161

6262
::: code-group
6363

64-
```php [Functional Mode]
64+
```php:no-line-numbers [Functional Mode]
6565
response()->plain('Hello, world!');
6666
```
6767

68-
```php [Leaf Instance]
68+
```php:no-line-numbers [Leaf Instance]
6969
$app->response()->plain('Hello, world!');
7070
```
7171

@@ -258,6 +258,38 @@ $app->response()->xml('<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
258258

259259
:::
260260

261+
### Custom responses
262+
263+
If you need to create a custom response, which is not covered by the methods above, you can use the `custom()` method. This method accepts 2 parameters:
264+
265+
- the content to output
266+
- an optional status code (defaults to 200/OK)
267+
268+
::: code-group
269+
270+
```php:no-line-numbers [Functional Mode]
271+
response()
272+
->withHeader([
273+
'Content-Type' => 'application/pdf',
274+
'Content-Length' => $dataLength,
275+
'Content-Disposition' => "inline; filename=\"$filename\""
276+
])
277+
->custom($rawData);
278+
```
279+
280+
```php:no-line-numbers [Leaf Instance]
281+
$app
282+
->response()
283+
->withHeader([
284+
'Content-Type' => 'application/pdf',
285+
'Content-Length' => $dataLength,
286+
'Content-Disposition' => "inline; filename=\"$filename\""
287+
])
288+
->custom($rawData);
289+
```
290+
291+
:::
292+
261293
## Headers
262294

263295
Headers are a way for your server to send additional information along with your request. This information can be anything from the type of content you're sending back, to the status code of your response, to the type of server you're using.

0 commit comments

Comments
 (0)