|
4 | 4 |
|
5 | 5 | ## 🪄 Usage - Examples
|
6 | 6 |
|
| 7 | +### Send Header By HTTP Code |
7 | 8 | ```php
|
8 | 9 | use PH7\PhpHttpResponseHeader\Header;
|
9 | 10 |
|
10 |
| -Http::setHeaders(200); // Sends "200 OK" header to the browser |
| 11 | +// Sends "200 OK" header to the browser |
| 12 | +Http::setHeadersByCode(200); |
11 | 13 |
|
| 14 | +// ... |
| 15 | + |
| 16 | +// Send "201 Created" header |
| 17 | +Http::setHeadersByCode(201); |
12 | 18 |
|
13 | 19 | // ...
|
14 | 20 |
|
15 |
| -Http::setHeaders(404); // Sends "404 Not Found" to the browser |
| 21 | +// Sends "404 Not Found" to the browser |
| 22 | +Http::setHeadersByCode(404); |
16 | 23 |
|
17 | 24 | // ...
|
18 | 25 |
|
19 |
| -Http::setHeaders(400); // Sends "400 Bad Request" to the browser |
| 26 | +// Sends "400 Bad Request" header to the browser |
| 27 | +Http::setHeadersByCode(400); |
| 28 | + |
20 | 29 |
|
21 | 30 | // and so on ...
|
22 | 31 | ```
|
23 | 32 |
|
| 33 | +**But, the library has many more handy methods such as below:** |
| 34 | + |
| 35 | +### Maintenance Code |
| 36 | +```php |
| 37 | +use PH7\PhpHttpResponseHeader\Header; |
| 38 | + |
| 39 | +// Send 503, Service Temporarily Unavailable to the browser mentioning that you are doing a maintenance (good practice!) |
| 40 | +Http::setMaintenanceCode($maintenanceTimeSeconds: 360); |
| 41 | +``` |
| 42 | + |
| 43 | +### Get HTTP Protocol |
| 44 | + |
| 45 | +```php |
| 46 | +use PH7\PhpHttpResponseHeader\Header; |
| 47 | + |
| 48 | +// The HTTP server protocol |
| 49 | +Http::getProtocol() |
| 50 | +``` |
| 51 | + |
| 52 | +### Set Content Type |
| 53 | +```php |
| 54 | +use PH7\PhpHttpResponseHeader\Header; |
| 55 | + |
| 56 | +// Send "Content-Type: application/json" header to the browser |
| 57 | +Http::setContentType("application/json"); |
| 58 | + |
| 59 | +// Send "Content-type: text/xml" to the browser |
| 60 | +Http::setContentType("text/xml"); |
| 61 | +``` |
| 62 | + |
| 63 | + |
24 | 64 | ## 🧑🍳 Who made this...?
|
25 | 65 |
|
26 | 66 | [](https://PH7.me 'Pierre-Henry Soria personal website')
|
|
0 commit comments