Google News
logo
Slim Framework - Interview Questions
What is the Request Method in Slim Framework?
Every HTTP request has a method that is typically one of:
 
* GET
* POST
* PUT
* DELETE
* HEAD
* PATCH
* OPTIONS

You can inspect the HTTP request’s method with the Request object method appropriately named getMethod().
$method = $request->getMethod();
It is possible to fake or override the HTTP request method. This is useful if, for example, you need to mimic a PUT request using a traditional web browser that only supports GET or POST requests.
 
There are two ways to override the HTTP request method. You can include a METHOD parameter in a POST request’s body. The HTTP request must use the application/x-www-form-urlencoded content type.
POST /path HTTP/1.1
Host: example.com
Content-type: application/x-www-form-urlencoded
Content-length: 22

data=value&_METHOD=PUT
 
You can also override the HTTP request method with a custom X-Http-Method-Override HTTP request header. This works with any HTTP request content type.
POST /path HTTP/1.1
Host: example.com
Content-type: application/json
Content-length: 16
X-Http-Method-Override: PUT

{"data":"value"}
Advertisement