You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-15
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,8 @@ Supported features:
24
24
25
25
***v4.x.x (LTS)**
26
26
* v3.x.x (Unsupported)
27
-
28
-
The versions *v2* and *v1* are not available in this repository, please consider an upgrade to the newer versions if you are still using them.
27
+
* v2.x.x (Unavailable)
28
+
* v1.x.x (Unavailable)
29
29
30
30
## Installation
31
31
@@ -70,26 +70,17 @@ After the configurations mentioned above, you can start using PhpRouter in your
70
70
71
71
```php
72
72
use MiladRahimi\PhpRouter\Router;
73
-
use Zend\Diactoros\Response\JsonResponse;
74
73
75
74
$router = new Router();
76
75
77
76
$router->get('/', function () {
78
77
return '<p>This is homepage!</p>';
79
78
});
80
79
81
-
$router->post('/blog/post/{id}', function ($id) {
82
-
return HtmlResponse("<p>This is a post $id</p>");
83
-
});
84
-
85
-
$router->patch('/json', function () {
86
-
return new JsonResponse(["message" => "posted data to user: $id"]);
87
-
});
88
-
89
80
$router->dispatch();
90
81
```
91
82
92
-
There are more examples [here](https://github.com/miladrahimi/phprouter/blob/master/examples/index.php).
83
+
There are more examples [here](https://github.com/miladrahimi/phprouter/tree/master/examples).
93
84
94
85
## HTTP Methods
95
86
@@ -266,7 +257,7 @@ $router->dispatch();
266
257
267
258
## HTTP Request and Request
268
259
269
-
PhpRouter uses [zend-diactoros](https://github.com/zendframework/zend-diactoros) package (v2) to provide [PSR-7](https://www.php-fig.org/psr/psr-7)complaint request and response objects to your controllers and middleware.
260
+
PhpRouter uses [zend-diactoros](https://github.com/zendframework/zend-diactoros) package (v2) to provide [PSR-7](https://www.php-fig.org/psr/psr-7) request and response objects to your controllers and middleware.
270
261
271
262
### Request
272
263
@@ -368,9 +359,9 @@ interface Middleware
368
359
}
369
360
```
370
361
371
-
As you can see, a middleware must have a `handle()` method that catches the request and a Closure (which is responsible for running the next middleware or the controller). It must return a response, as well. A middleware can break the lifecycle and return the response or it can run the `$next` closure to continue the lifecycle.
362
+
As you can see, a middleware must have a `handle()` method that catches the request and a Closure (which is responsible for running the next middleware or the controller). It must return a response, as well. A middleware can break the lifecycle and return a response or it can run the `$next` closure to continue the lifecycle.
372
363
373
-
See the following example. In this snippet, if there is an `Authorization` header in the request, it passes the request to the next middleware or the controller (if there is no more middleware left) and if the header is absent, it returns an empty response with `401 Authorization Failed ` HTTP status code.
364
+
See the following example. In the implemented middelware, if there is an `Authorization` header in the request, it passes the request to the next middleware or the controller (if there is no more middleware left) and if the header is absent, it returns a JSON response with `401 Authorization Failed ` HTTP status code.
0 commit comments