开发者

RESTful way to "pay for product"

开发者 https://www.devze.com 2023-02-21 11:37 出处:网络
I\'m designing the architecture for my e-commercial sites. I\'开发者_运维百科ve designed RESTful interface for product management, but the feature \"pay for product\" is not so natural in RESTful way

I'm designing the architecture for my e-commercial sites. I'开发者_运维百科ve designed RESTful interface for product management, but the feature "pay for product" is not so natural in RESTful way in my opinion. Could someone give me an idea? How to design it?


Paying for things is not idempotent; users really care how often it happens. As such, it maps to a POST in the RESTful model. That can then result in the creation of a record of the transaction which can be handled by GET, etc.


Fortunately, one of the popular teaching examples for REST deals with a customer interaction - How to GET a Cup of Coffee. Reading that should give you a sense for how you should design your interface for paying for a product, using a RESTful architecture.

In a RESTful design, the client is will be guided through the process by hypermedia.


The resource-oriented architecture focuses on nouns rather than verbs (vs. remote method invocation and service-oriented architecture). Taking a hint from Donal Fellows' answer, the RMI idea is "pay for a product"; the RESTful idea is "create a transaction". This is a "transaction" in the sense of buying something at a store, but it is related to the database kind of "transaction".

You can also think of the familiar "shopping cart" as a RESTful resource, and the product itself is a RESTful resource. It's perfectly OK for the RESTful resources to be able to "do things", like:

POST /cart/{id of cart}/acceptproduct/{id of product}

Although you could do something like this:

GET /cart/{id of cart}

(add products to the representation of the cart)

PUT /cart/{id of cart}

The user's charge account is yet another RESTful resource, to which you can post charges. (Pun intended.)

0

精彩评论

暂无评论...
验证码 换一张
取 消