Can I simulate a PUT or DELETE request using a POST request with Sinatra?

Some web browsers cannot make PUT or DELETE requests, but I need to make them for my REST service written in Ruby using Sinatra. Is it possible to make Sinatra interpret the POST request as a PUT or DELETE request?

+4
source share
2 answers

Read the document and find the description of method_override . The mechanism is identical to Rails. If your browser does not support PUT and DELETE , just send an additional parameter named _method with a value of PUT or DELETE .

Note that in the Modular application (your class inherits Sinatra::Base ), method_override disabled by method_override . You need to enable it manually.

+8
source

All current web browsers support PUT and DELETE in XMLHttpRequest. In addition, as far as I know, no browser supports them in HTML forms, mainly because it has not yet specified what they will do exactly.

+3
source

Source: https://habr.com/ru/post/1383445/


All Articles