Paweł Miczka
Paweł Miczka

Reputation: 145

Method name as POST parameter in Laravel API

I want to make Laravel RESTful API and also i have something that can send request to www but there is problem - this THING can send only GET and POST. Is there way to configure Laravel to know that i sent method name as a parameter for ex. in _method parameter and redirect to proper Route (i prefer making Route::resource so that's why i'm asking)?

Upvotes: 0

Views: 870

Answers (1)

Yoram
Yoram

Reputation: 602

This is called Method Tunneling through POST.

In many scenarios clients are limited to the HTTP GET and POST methods only. In order to help work-around this limitation, RESTful servers can support method tunneling through POST. The methods that can be executed through tunneling are MERGE, PUT and DELETE.

To issue a request with method tunneling a client sets up a request with body and headers as needed, but uses POST as the HTTP method instead of the actual required one. It then adds one more header, "X-HTTP-Method", and gives it the value MERGE, PUT or DELETE.

Servers must check if POST requests have the X-HTTP-Method header set to one of the valid values and if so execute the rest of the request as if the header value was the actual HTTP method for it.

Upvotes: 2

Related Questions