(GET, POST, etc)method and methodOnlyWe can specify that a route is only valid for specific HTTP request methods by using the method guard:
The method guard does two things:
Here is a simple demo app:
[Source code for the app is here.]
Using curl we can see the expected results for normal GET and POST requests to /:
$ curl http://localhost:8000/ You did a GET request. $ curl -d '' http://localhost:8000/ You did a POST request.
Note that method also requires that the all the segments of request path have been consumed. We can see in here that /foo is accepted, but not /foo/bar, since only foo is consumed by the, dir "foo" filter.
$ curl http://localhost:8000/foo You did a GET request on /foo $ curl http://localhost:8000/foo/bar <404 message>
If we want to allow unconsumed path segments we can use methodOnly instead.
In fact the definition for method is simply: