New to web development, my understanding is that GET is used to get user input and POST to give them output. If I have a hybrid page, eg. on StackOverflow, if I write a question, it POSTs a page with my question, but also has a text box to GET my answer. In my routes file, what method would the URL associated with my postQgetA() method specify - GET or POST?
1 Answers
From technical point of view you can use only GET
to perform almost every operation, but...
GET
is most common method and it's used when you ie. click on the link, to get data (and do not modify it on server), optionally you send id of the resource to get (if you need to get data of single user).POST
is most often used to sendingnew
data to the server ie. fromform
- to store them in your database (or proccess in any other way)
There are also other request methods (ie. DELETE
, PUT
) you can use with Play, however some of them need to be 'emulated' via ie. ajax, as there is not possible to set method of the common link ie. to DELETE
. It's described how to use non-GET/POST methods in Play! (Note, that Julien suggests there, using GET for delete
action although is possible it's a broken semantics.)
There are also other discussions on StackOverflow where you can find examples and suggestions for choosing correct method for your routes.
BTW, if you sending some request, let's say it's POST
you don't need to perform separate GET
as sending a request
generates a response
in other words, after sending new question with POST
first you're trying to save it to DB, if no errors render the page and send it back in response.