1

In my Rails application I have an url routed to an action in charged of showing or creating (if not existing) e resource. What is the appropriate http verb to use for this kind of request?

To be more precise, in my method I don't directly access the resource but I use a library which has that behavior: first search and then create the resource if not exiting. My method, in the end, always provide the resource returned by the library either a brand new one or an old one. Hence I cannot split into two requests.

According to this and considering my method always returns the same resource (idempotent) it seems that PUT should be the right one. I just wonder whether PUT can be used in case where e resource is actually just retrieved (get) and anything is not even updated

tnx

Community
  • 1
  • 1
masciugo
  • 1,113
  • 11
  • 19

4 Answers4

0

According to Ruby on Rails guides, you should use GET and POST verbs. More information here: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

Dima Knivets
  • 2,418
  • 7
  • 28
  • 40
0

POST for creating, GET for showing is automatically used by rails. But I hope you can do all sorts of things with custom programming as data will be available to you in form of params[]

Neeraj
  • 180
  • 9
0

You use GET to retrieve.
If resource found return 200 with resource. If resource not found let it return 404 and check the error code and use POST and create the resource.

Satish
  • 713
  • 1
  • 5
  • 18
0

If you donot need any parameter while creating resource then you should use GET request Else if you need params while creating resource , then you should make separate action for creating(Post request with params) and showing(GET request) resource.

Anil Maurya
  • 2,298
  • 1
  • 22
  • 28