如何在 RESTful Web 应用程序中创建新的 HttpSession?
每当客户端调用特定的 UI 时,我都需要创建一个 HttpSession (通过 cookie)。
假设:
- 假设我不会担心任何类似 oAuth 的深层身份验证。 JESSIONSID cookie 模拟目前不是问题。
- 服务器是 tomcat,因此如果创建新会话,则会将 JSESSIONID cookie 发送到客户端。
设计问题:
- 我正在努力解决如何设计 URI。 REST 资源实际上是什么? 我已经有 /users 和 /users/{someuserid}。 我想使用 /auth/login 但在之前的一个问题中,一篇引用的文章 表示我们不应在 url 中包含动词。 我注意到,即使 Google 也会犯同样的错误< /a> 通过https://www.google.com/accounts/OAuthGetRequestToken。 那么您认为 /auth/login/johndoe (登录)和 /auth/logout/johndoe (注销)是不错的选择吗?
更新:
我改变了我的设计。 我现在正在考虑使用 URI /session/johndoe(PUT 用于登录,DELETE 用于注销)。 它仍然应该在 REST 精神的范围内吗?
I have a need to create a HttpSession (via cookie) whenever a client invokes a particular UI.
Assumptions:
- Let's assuming that I'm not going to worry about any deep oAuth-like authentication dance. JESSIONSID cookie impersonation is not an issue for now.
- The server is tomcat, thus a JSESSIONID cookie is sent down to the client if a new session is created.
Design issues:
- I'm grappling with how to design the URI. What is actually the REST resource ? I already have /users and /users/{someuserid}. I wanted to use /auth/login but in one previous SO question, one cited article says that we should not have verbs in the url. I've noticed that even Google makes the same mistake by having https://www.google.com/accounts/OAuthGetRequestToken. So in your opinion, are /auth/login/johndoe (login) and /auth/logout/johndoe (logout) good options ?
UPDATE:
I've changed my design. I'm now thinking of using the URIs /session/johndoe (PUT for login, DELETE for logout). It should still be within the limits of the REST ethos ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
会话在 REST 风格架构中不是无关紧要的吗?
http://www.prescod.net/rest/mistakes/
Aren't sessions irrelevant in REST Style Architecture?
http://www.prescod.net/rest/mistakes/
我正在创建一个识别会话的 REST 端点。 我已经标准化:
它运行良好。
I am in the midst of creating a REST endpoint that recognizes sessions. I've standardized on:
It is working well.