我当时在设计一个Web应用程序,然后停下来思考如何将我的api设计为RESTful Web服务。目前,我的大多数URI都是通用的,可能适用于各种Web应用程序:
GET /logout // destroys session and redirects to /
GET /login // gets the webpage that has the login form
POST /login // authenticates credentials against database and either redirects home with a new session or redirects back to /login
GET /register // gets the webpage that has the registration form
POST /register // records the entered information into database as a new /user/xxx
GET /user/xxx // gets and renders current user data in a profile view
POST /user/xxx // updates new information about user
在SO和google上闲逛之后,我觉得自己在这里做错了很多。
从开始/logout
,也许因为我实际上GET
什么都不是-它可能更适合于POST
请求/logout
,销毁会话,然后GET
重定向。这个/logout
词应该保留吗?
那/login
和/register
。我可以更改/register
为,/registration
但这不会改变我的服务的基本工作原理-如果它存在更深的问题。
我现在注意到,我从不公开/user
资源。也许可以以某种方式加以利用。例如,以用户myUser
:
foo.com/user/myUser
要么
foo.com/user
最终用户不需要URI中的额外详细信息。但是,哪一个在视觉上更有吸引力?
我在这里注意到关于REST业务的其他问题,但是如果可能的话,我真的很感谢我在这里提出的一些指导。
谢谢!
更新:
我还希望就以下问题发表意见:
/user/1
与
/user/myUserName