What are HTTP methods (verbs) for?

Robo Robok

I have read several sources about HTTP methods, but I still don't understand clearly the simplest thing: what are they for?

Each source I've seen points out when particular methods should be used, but what does it change in practice? Is there any difference how the request is being handled between, let's say, GET and POST?

Or maybe those methods are there to allow us to handle multiple behaviors on one URL?

And finally, what about the browsers? Forms can only make GET and POST requests and they handle them in different way. POST form sends data "in the background", while GET passes them in the URL. Does it have anything to do with the protocol or is it just browsers' convention?

Thank you in advance for clarifying it for me. :)

deceze

Fundamentally, yes, methods are there to allow different "interactions" with every "entity". HTTP is designed so you can think of each URL as one entity.

  • /users represents all users
  • /users/dave represents one specific user
  • POST /users lets you create a new user
  • PUT /users/dave lets you modify a specific user
  • GET /users gets you a list of users
  • GET /users?name=dave lets you query for a list of users named "dave"

and so on...

That's the way HTTP was designed to be used, each verb has a specific implied meaning. You can use those verbs any way you want really, but GET implies "passive" information retrieval, while POST, PUT and DELETE imply destructive changes.

Browsers and other clients do handle these differently. It's expected that anything GET can be requested at any time any number of times, can be cached, can be pre-fetched, can be queried mostly out of order. More destructive actions should be performed only once when requested and not cached, pre-fetched or anything else. A browser will explicitly ask for confirmation if you're "reloading" a page requested via POST.

POST form sends data "in the background", while GET passes them in the URL. Does it have anything to do with the protocol or is it just browsers' convention?

"In the background" is the wrong way of thinking. The difference is between the URL and the request body. A GET request should not/must not have anything in its request body. Again, it's only passive information retrieval and must solely consist of HTTP headers. A POST request can have a request body. A request can have "data" both in its URL and in its body. Again, an assumption is that GET URLs can be shared and passed around, since it just links to information. POST requests on the other hand need to be very deliberate, so its information should not and doesn't need to be in the URL.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

What is idempotency in HTTP methods?

From Dev

Where in a HATEOAS architecture do you specify the HTTP verbs?

From Dev

What are the PCIe operations involved in Infiniband verbs?

From Dev

Unit Test to ensure only selected HTTP verbs are applicable to WebAPI

From Dev

What is the difference between POST and PATCH verbs and when would I use the former over the latter?

From Dev

Why use HTTP verbs?

From Dev

Limit HTTP verbs without redundant config

From Dev

Trouble testing HTTP verbs with PHPUnit in Laravel

From Dev

Rails routes - override http verbs

From Dev

What Http response code should I return for validation-only API methods?

From Dev

Grails 3.0.11 mapping HTTP verbs

From Dev

what are the difference in ruby methods

From Dev

What is the difference between setter methods and constructor methods?

From Dev

What is the difference between inherited methods and public methods?

From Dev

Who decided the usage of the HTTP verbs on the REST architecture

From Dev

RBAC for openstack via http verbs proxy

From Dev

Vim: What do these short names / verbs like <leader>, <C-r> mean?

From Dev

Really custom urls for backbone models http verbs

From Dev

Why use HTTP verbs?

From Dev

What are getter and setter methods?

From Dev

What are HTTP methods (verbs) for?

From Dev

what methods are there to classify documents?

From Dev

What Http response code should I return for validation-only API methods?

From Dev

Express js delegate http verbs

From Dev

Is there a way to tell what verbs are more efficient

From Dev

Best ways of handling http verbs in a directive

From Dev

The URI contains HTTP action verbs. Can I consider this API RESTful?

From Dev

Do regex understand what adjectives and verbs are?

From Dev

Are other HTTP methods necessary?

Related Related

  1. 1

    What is idempotency in HTTP methods?

  2. 2

    Where in a HATEOAS architecture do you specify the HTTP verbs?

  3. 3

    What are the PCIe operations involved in Infiniband verbs?

  4. 4

    Unit Test to ensure only selected HTTP verbs are applicable to WebAPI

  5. 5

    What is the difference between POST and PATCH verbs and when would I use the former over the latter?

  6. 6

    Why use HTTP verbs?

  7. 7

    Limit HTTP verbs without redundant config

  8. 8

    Trouble testing HTTP verbs with PHPUnit in Laravel

  9. 9

    Rails routes - override http verbs

  10. 10

    What Http response code should I return for validation-only API methods?

  11. 11

    Grails 3.0.11 mapping HTTP verbs

  12. 12

    what are the difference in ruby methods

  13. 13

    What is the difference between setter methods and constructor methods?

  14. 14

    What is the difference between inherited methods and public methods?

  15. 15

    Who decided the usage of the HTTP verbs on the REST architecture

  16. 16

    RBAC for openstack via http verbs proxy

  17. 17

    Vim: What do these short names / verbs like <leader>, <C-r> mean?

  18. 18

    Really custom urls for backbone models http verbs

  19. 19

    Why use HTTP verbs?

  20. 20

    What are getter and setter methods?

  21. 21

    What are HTTP methods (verbs) for?

  22. 22

    what methods are there to classify documents?

  23. 23

    What Http response code should I return for validation-only API methods?

  24. 24

    Express js delegate http verbs

  25. 25

    Is there a way to tell what verbs are more efficient

  26. 26

    Best ways of handling http verbs in a directive

  27. 27

    The URI contains HTTP action verbs. Can I consider this API RESTful?

  28. 28

    Do regex understand what adjectives and verbs are?

  29. 29

    Are other HTTP methods necessary?

HotTag

Archive