Is it good to implement REST api using Sessions?

2020-02-13 05:26发布

A REST client usually send an authentication parameter every time which acts like PHP Session Id cookie in browser in a way. But REST client is no browser so I though in my server side code why not I take that authentication parameter and use

session_id($_GET('authentication_code'));

Is it good way of doing it ??

标签: php session rest
2条回答
不美不萌又怎样
2楼-- · 2020-02-13 05:38

The answer is no. The S REST is for stateless which means you cannot store anything on the server.

查看更多
我想做一个坏孩纸
3楼-- · 2020-02-13 05:45

REST stands for Representation State Transfer and in it's purest form boils down to 6 constraints, one of which is that the client-server communication must be stateless, it must contain all the information needed to complete the request, no client state must be stored on the server.

The server CAN be statefull however, which is why you can store a client's auth code on the server, but it is up to the client itself to pass that code with each request, the server cannot use sessions to store the authentication code.

查看更多
登录 后发表回答