40

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
  • 40,752
  • 27
  • 129
  • 174
onassar
  • 3,313
  • 7
  • 36
  • 58

2 Answers2

61

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
  • 40,752
  • 27
  • 129
  • 174
  • 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
-5

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.

xosg
  • 89
  • 1
  • 6