休息购物车 [英] REST Shopping cart

查看:45
本文介绍了休息购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用 REST 架构约束来实现购物车吗?

Can a shopping cart be implemented using REST architecture constraints?

我想将我的问题集中在会话状态方面.在实现购物车的典型 MVC 应用程序中,很可能会在会话中管理会话对象,将购物车作为产品列表进行管理.

I would like to focus my question with respect to session state. In a typical MVC application implementing a shopping cart, it most likely, session object will be managed in session, shopping cart as a list of products.

如果应用程序遵循 REST 架构,将如何管理同一个购物车.REST 约束之一是状态管理是客户端的责任.

How would this same shopping cart be managed in if the application had followed REST architecture. One of the REST constraints is state management is responsibility of clients.

应该由客户管理购物车及其进度吗?有什么例子吗?与简单的购物车或任何其他企业应用程序相比,在客户端管理状态有什么缺点吗?

Should a shopping cart and it's progress be managed by client? Any examples? Any disadvantages of managing state in client with respect to a simple shopping cart or any other enterprise applications?

推荐答案

将购物车作为资源存储在服务器上没有任何问题.会话状态应该存储在客户端上.https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_3

There is nothing wrong with storing the shopping cart as a resource on the server. It is session state that should be stored on the client. https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_3

为了实现无状态,您的购物车 URI 应该能够识别唯一的购物车,而无需依赖任何会话信息.

In order to be stateless, your shopping-cart URI should be able to identify a unique cart without needing to rely on any session information.

例如,/shopping-cart 可能是不够的,除非整个应用程序中只有一个购物车.

For example, /shopping-cart is probably not sufficient unless there will only ever be one shopping cart throughout your application.

很可能,每个用户至少有一个购物车.因此,您可以使用 /user/1234/shopping-cart/shopping-cart?userID=1234 之类的内容.

Likely, there will be at least one cart per user. So, you could use something like /user/1234/shopping-cart or /shopping-cart?userID=1234.

更有可能的是,您可能需要为每个用户拥有多个购物车.因此,您需要为您的购物车提供一个唯一 ID,例如 /user/1234/shopping-cart/5678/shopping-cart/5678.

Even more likely, you will probably need to have multiple shopping-carts per user. So, you will want to give your carts a unique ID like /user/1234/shopping-cart/5678 or just /shopping-cart/5678.

关键是,处理请求所需的一切都应该在请求中.

The point is, everything needed to process the request should be in the request.

这篇关于休息购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆