Skip to content

Commit 7a60487

Browse files
committed
Update examples / code snippets
1 parent ef7b60c commit 7a60487

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

README.md

+43-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,63 @@
44

55
## 🪄 Usage - Examples
66

7+
### Send Header By HTTP Code
78
```php
89
use PH7\PhpHttpResponseHeader\Header;
910

10-
Http::setHeaders(200); // Sends "200 OK" header to the browser
11+
// Sends "200 OK" header to the browser
12+
Http::setHeadersByCode(200);
1113

14+
// ...
15+
16+
// Send "201 Created" header
17+
Http::setHeadersByCode(201);
1218

1319
// ...
1420

15-
Http::setHeaders(404); // Sends "404 Not Found" to the browser
21+
// Sends "404 Not Found" to the browser
22+
Http::setHeadersByCode(404);
1623

1724
// ...
1825

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+
2029

2130
// and so on ...
2231
```
2332

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+
2464
## 🧑‍🍳 Who made this...?
2565

2666
[![Pierre-Henry Soria](https://s.gravatar.com/avatar/a210fe61253c43c869d71eaed0e90149?s=200)](https://PH7.me 'Pierre-Henry Soria personal website')

0 commit comments

Comments
 (0)