Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit b4eb3ee

Browse files
committed
Documents new XmlResponse
Uses same basic structure as HtmlResponse documentation, with updates to indicate usage is with XML.
1 parent 49ca8d5 commit b4eb3ee

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/book/custom-responses.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ $response = new HtmlResponse($htmlContent, 200, [ 'Content-Type' => ['applicatio
5858
Headers must be in the same format as you would provide to the
5959
[Response constructor](api.md#response-message).
6060

61+
## XML Responses
62+
63+
- Since 1.7.0
64+
65+
`Zend\Diactoros\Response\XmlResponse` allows specifying XML as a payload, and sets the
66+
`Content-Type` header to `application/xml` by default:
67+
68+
```php
69+
$response = new XmlResponse($xml);
70+
```
71+
72+
The constructor allows passing two additional arguments: a status code, and an array of headers.
73+
These allow you to further seed the initial state of the response, as well as to override the
74+
`Content-Type` header if desired:
75+
76+
```php
77+
$response = new XmlResponse($xml, 200, [ 'Content-Type' => ['application/hal+xml']]);
78+
```
79+
80+
Headers must be in the same format as you would provide to the
81+
[Response constructor](api.md#response-message).
82+
6183
## JSON Responses
6284

6385
`Zend\Diactoros\Response\JsonResponse` accepts a data structure to convert to JSON, and sets

0 commit comments

Comments
 (0)