38

Curious how others here would represent these in a REST architecture.

/users/login/
/users/logout/

These endpoints set up the session to login in the user, or clear it, respectively. My gut says POST, but I'm not in fact creating an object.

Yaakov Ellis
  • 39,558
  • 26
  • 126
  • 172
onassar
  • 2,976
  • 6
  • 35
  • 53

2 Answers2

58

You should use POST - using GET for these actions can lead to issues with browser prefetching and search engine spidering. See (1, 2)

Community
  • 1
  • 1
Yaakov Ellis
  • 39,558
  • 26
  • 126
  • 172
  • Concise, it was not necessary to make a research on it. Thanks – technology_dreamer May 23 '15 at 19:47
  • Yes, `POST` sounds like the most rational option for a logout request and is what I would consider by default, however, doesn't `POST` mean "create"? What form-data would you be sending for a logout request with `POST`? A `DELETE` request would hardly be suitable either unless you have something like `DELETE /session/{id}`. `PUT` would mean we're replacing something, so that's out of the question. What are your thoughts on `PATCH`? – undefined Mar 06 '21 at 10:01
-4

maybe CONNECT? MDN says:

The HTTP CONNECT method starts two-way communications with the requested resource. It can be used to open a tunnel.

as login means maintaining a session between browser and server, CONNECT method makes the most sense.

Jim
  • 41
  • 4