如何在 RESTful Web 应用程序中创建新的 HttpSession?

发布于 2024-07-17 15:29:08 字数 1074 浏览 5 评论 0原文

每当客户端调用特定的 UI 时,我都需要创建一个 HttpSession (通过 cookie)。

假设:

  • 假设我不会担心任何类似 oAuth 的深层身份验证。 JESSIONSID cookie 模拟目前不是问题。
  • 服务器是 tomcat,因此如果创建新会话,则会将 JSESSIONID cookie 发送到客户端。

设计问题:

  1. 我正在努力解决如何设计 URI。 REST 资源实际上是什么? 我已经有 /users/users/{someuserid}。 我想使用 /auth/login 但在之前的一个问题中,一篇引用的文章 表示我们不应在 url 中包含动词。 我注意到,即使 Google 也会犯同样的错误< /a> 通过https://www.google.com/accounts/OAuthGetRequestToken。 那么您认为 /auth/login/johndoe (登录)和 /auth/logout/johndoe (注销)是不错的选择吗?

更新:

我改变了我的设计。 我现在正在考虑使用 URI /session/johndoePUT 用于登录,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:

  1. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

杀手六號 2024-07-24 15:29:08

会话在 REST 风格架构中不是无关紧要的吗?

http://www.prescod.net/rest/mistakes/

Aren't sessions irrelevant in REST Style Architecture?

http://www.prescod.net/rest/mistakes/

街角卖回忆 2024-07-24 15:29:08

我正在创建一个识别会话的 REST 端点。 我已经标准化:

它运行良好。

I am in the midst of creating a REST endpoint that recognizes sessions. I've standardized on:

It is working well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文