I give an common user login/logout example about discussing HTTP method and status code. I hope It can help people to understand easily.
Traditional no restful api design:
When user login/logout a website, it's sure to access backend service by HTTP request of
POSTmethod.
It's beyond question.
But if I follow restful api design pattern, is still it be designed?
My thought is:
- Login
Loginwill generate a token key when user login. I think it's a creation action for database because generating a token key, so should it return201 Createdstatus code?
- Logout
Relatively,
Logoutwill delete the token key when user send his token and do logout. I think it's a deletion action for db because deleting the token key, so should it return204 No contentstatus code?
Although I think it maybe fits in with HTTP method meaning, if I will offer or share this API design, does it make other developer confuse?
I don't know this idea is or isn't good. I want to listen your opinion.