How to determine the HTTP method and login and logout status code?

I give a general example of user login / logout for discussion HTTP methodand status code. Hope this helps people understand easily.


Traditional carefree api design:

When a user logs in / logs out to a website, he will definitely get access to the server service by the HTTP request of the method POST.

This is beyond doubt.


But if I follow the resty api design template, will it still be designed?

My thought:

  • To come in

Loginwill generate a token key when a user logs in. I think this is an action to create a database, because it generates a token key, so should it return a status code 201 Created?

  • Exit

Logout , . , db, , 204 No content ?

, , , HTTP, API, ?

, . .

+4
1

, , , . , , 200, 201 204, code >= 200 && code < 300. . , 201 204, - .

. POST /login login, POST /items, item, API . a 200 OK , , . , , 200 .

+3

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


All Articles