Some questions of restful

UserController

user
id mobile password
user_info 
uid nickname sex avatar 

--
function actionLogin()

end

--
function actionRegister()
 
end

--
function actionSignOut()

end

--
function actionModifyPassword()

end

--
function actionInfo()

end

restful url
/user/register  post /users
/user/login 
/user/sign-out   put /users 
/user/modify-password  put /users
/user/info  get /users/id/info 
,  UserInfoControler get user-infos

restful
Aug.31,2021

Don't think of restful as not using verbs in url, you can think of login as a service, post / login is fine.
to understand restful, you have to go to Representational State Transfer what each word refers to. Representational representation (figurative) refers to the way the resource (resource) shows you.
state status refers to the current state of the resource. Any addition, deletion or modification can be understood as changing the state of the resource, for example, from one item of user data to two, and the name of a user is changed.
transfer refers to the process of state change. How to transfer such a change from the client to the server is to tell the server how to change the state of the resource through the four verbs of GET, POST, PUT and DELETE, of http.
the premise of understanding this is that you have to think of uri as a resource, which can be an entity class (user), or a service (login), so we should try to convert verbs to nouns, but here login is obviously more clear with verbs, so it doesn't matter if we use verbs.
of course, rest also has some other constraints, such as using the status code of http to represent the status of the operation, such as the use of json format for data transmission, and so on.

Menu