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.
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.
You should use POST - using GET for these actions can lead to issues with browser prefetching and search engine spidering. See (1, 2)
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?Use POST.
Logout changes the state on the server (e.g., destroying a session, invalidating a token), so it should not be GET. POST is used for operations that cause side effects and are not idempotent — which logout usually is. It's semantically correct for actions like logout that do not delete a resource, but still trigger a state change.