RESTful way to "pay for the product"

I design the architecture for my e-commerce sites. I have developed a RESTful interface for product management, but the "pay for product" function is not so natural in RESTful in my opinion. Can anyone give me an idea? How to create it?

+4
source share
3 answers

Payment for things is not idempotent; users really care about how often this happens. Thus, it displays the POST in the RESTful model. This can lead to the creation of a transaction record that can be processed by GET, etc.

+4
source

Fortunately, one of the most popular examples of REST training relates to customer interaction - How to get a cup of coffee . A read that should give you an idea of ​​how you should design your interface to pay for the product using the RESTful architecture.

In a RESTful design, the client will go through the hypermedia process.

+2
source

A resource-oriented architecture focuses on nouns rather than verbs (against remote method invocation and service-oriented architecture). Accepting a hint at Donald Fellows' response, RMI's idea is to "pay for the product"; RESTful's idea is to create a transaction. This is a “transaction” in the sense of buying something in a store, but it is related to the type of database transaction.

You can also think of the familiar “shopping basket” as a RESTful resource, and the product itself is a RESTful resource. It is perfectly normal for RESTful resources to "do something", for example:

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

Although you can do something like this:

 GET /cart/{id of cart} 

(add products to cart view)

 PUT /cart/{id of cart} 

A user account is another RESTful resource to which you can publish payments. (Pun intended.)

0
source

Source: https://habr.com/ru/post/1346414/


All Articles