Skip to content

Commit 8d08844

Browse files
committed
Update description to README.md
1 parent a34afa6 commit 8d08844

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

README.md

+46-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
This package contains a collection of classes that implements [Psr\Http\Message\ResponseInterface](https://github.com/php-fig/http-message/blob/master/src/ResponseInterface.php) from [PSR-7 HTTP Message](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md) in accordance with the [RFC 7230](https://tools.ietf.org/html/rfc7230) and [RFC 7231](https://tools.ietf.org/html/rfc7231) specifications.
1111

12+
Depends on the [httpsoft/http-message](https://github.com/httpsoft/http-message) package.
13+
1214
## Documentation
1315

1416
* [In English language](https://httpsoft.org/docs/response).
@@ -22,7 +24,50 @@ This package requires PHP version 7.4 or later.
2224
composer require httpsoft/http-response
2325
```
2426

25-
## Usage
27+
## Usage standard response
28+
29+
```php
30+
use HttpSoft\Message\Response;
31+
32+
$response = new Response();
33+
// default values
34+
$response->getStatusCode(); // 200
35+
$response->getReasonPhrase(); // 'OK'
36+
$response->getBody()->getContents(); // ''
37+
$response->getBody()->getMetadata('uri') // 'php://temp'
38+
$response->getHeaders(); // []
39+
$response->getProtocolVersion(); // '1.1'
40+
41+
// Create with the passed parameters
42+
$response = new Response(404, ['Content-Language' => 'en'], 'php://memory', '2');
43+
$response->getStatusCode(); // 404
44+
$response->getReasonPhrase(); // 'Not Found'
45+
$response->getBody()->getContents(); // ''
46+
$response->getBody()->getMetadata('uri') // 'php://memory'
47+
$response->getHeaders(); // ['Content-Language' => ['en']]
48+
$response->getProtocolVersion(); // '2'
49+
50+
// Write to the response body:
51+
$response->getBody()->write('Content');
52+
$response->getBody()->getContents(); // 'Content'
53+
54+
// With `Content-Type` header:
55+
$newResponse = $response->withHeader('Content-Type', 'text/plain');
56+
$newResponse->getHeaderLine('content-type'); // 'text/plain'
57+
$newResponse->getHeaders(); // ['Content-Language' => ['ru'], 'Content-Type' => ['text/plain']]
58+
59+
// With status code:
60+
$newResponse = $response->withStatus(500);
61+
$newResponse->getStatusCode(); // 500
62+
$newResponse->getReasonPhrase(); // 'Internal Server Error'
63+
64+
// With status code and reason phrase:
65+
$newResponse = $response->withStatus(599, 'Custom Phrase');
66+
$newResponse->getStatusCode(); // 599
67+
$newResponse->getReasonPhrase(); // 'Custom Phrase'
68+
```
69+
70+
## Usage custom responses
2671

2772
```php
2873
// Create `Psr\Http\Message\ResponseInterface` instance from HTML:

0 commit comments

Comments
 (0)