Reputation: 601
I am creating an API and I would like to distinguish GET, DELETE, MODIFY, POST requests.
Is it possible to distinguish that from a controller?
For example:
Distinguish: (GET REQUEST)
GET http://myapi.com/POST/1234
From DELETE REQUEST
DELETE http://myapi.com/POST/1234
Can I do that from post controller?
Thanks
Upvotes: 3
Views: 213
Reputation: 46193
If you map your routes RESTfully (see this tutorial), the DELETE verb on that resource will map to a different controller action than the GET request.
GET maps to show
and DELETE maps to destroy
.
Upvotes: 2
Reputation: 40333
Inside a controller action method, do:
request.method
It's going to say which HTTP method was used.
You can also use:
request.get?
request.post?
request.delete?
And so on.
For full documentation on the class, check here.
Upvotes: 3