Play Framework - GET vs POST

New to web development, I understand that GET is used to get user input and POST to give them a way out. If I have a hybrid page, for example. on StackOverflow, if I write a question, it will send a page with my question, but it also has a text box to get an answer. In the routes file, which method will indicate the URL associated with my postQgetA () method - GET or POST?

+4
source share
1 answer

From a technical point of view, you can only use GET to perform almost every operation, but ...

  • GET is the most common method, and it is used when you do this. click on the link to get the data (and not change it on the server), if necessary, you send the identifier of the resource that you want to receive (if you need to get the data of one user).
  • POST most often used to send new data to the server, i.e. from form - save them in your database (or execute them in any other way).

There are other request methods (ie DELETE , PUT ) that you can use with Play, however some of them need to be "emulated" through i.e. ajax, since it is not possible to set the shared link method, i.e. until DELETE . He described how to use non-GET / POST methods in Play! (note that Julien suggests there, using GET to DELETE actions, although maybe it's broken semantics.)

There are other discussions in StackOverflow where you can find examples and suggestions on choosing the right method for your routes.

BTW, if you send a request, say POST you do not need to perform a separate GET , since sending a request generates a response other words, after sending a new question using POST , you first try to save it to the database if no errors display the page and Do not send it back.

+3
source

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


All Articles