Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get and post request for the same match

In my routes file I have:

match 'graphs/(:id(/:action))' => 'graphs#(:action)'

and I would like to match this if it is GET request (working) or POST request (not working)

I know that I can declare POST request inside a resource using:

post '/' => :show, :on => :member

But how can I do that for a match ?

Thanks.

like image 840
glarkou Avatar asked Aug 08 '11 11:08

glarkou


People also ask

Can we use GET and POST interchangeably?

In some applications, the HTTP methods GET and POST can be used interchangeably. For example, the application may expect a POST request, and the frontend will also send the data in a POST request, but if the request is tampered with, the data will also be accepted in a GET request.

What is difference between GET request and POST request?

HTTP POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all required data in the URL.

Which is Better GET or POST in terms of security?

The GET request is marginally less secure than the POST request. Neither offers true "security" by itself; using POST requests will not magically make your website secure against malicious attacks by a noticeable amount. However, using GET requests can make an otherwise secure application insecure.

Can we use GET method to POST data?

GET can't be used to send word documents or images. GET requests can be used only to retrieve data. The GET method cannot be used for passing sensitive information like usernames and passwords. The length of the URL is limited.


1 Answers

if you want for both POST and GET

match 'graphs/(:id(/:action))' => 'graphs#(:action)', :via => [:get, :post]

Edit

defaults can be set as following

match 'graphs/(:id(/:action))' => 'graphs#(:action)', :via => [:get, :post],
                                                      :defaults => { :action => "index" }

and the syntax seems to be correct

like image 105
Bohdan Avatar answered Oct 05 '22 05:10

Bohdan