View order-REST process API design case (2)

Source: Internet
Author: User

 

This is too simple. Where is the process?

In the above example, we see the order CRUD operation, but this is not the real situation in real life, the entire order lifecycle is shown in:

 

To achieve this process, we can take two steps: Step 1: model the order resources, and Step 2: Manage the lifecycle of the order process through the workflow.

 

A workflow is responsible for managing the lifecycle of an order. At different stages of its lifecycle, we have different participants who have different operation permissions on the order. Our system architecture has evolved into the following:

Let's look at the example. This time, we will move our perspective to the box network to see how the box handles the orders we have submitted. We use GET: http://api.kuangkuang.com/orders? Status = waiting-review:


Xml Code
<Orders>
<Link rel = "list" media-type = "application/xml" url = "http://api.kuangkuang.com/orders"/>
<Order>
<Id> 1000 </id>
<State> waiting review </state>
<Link rel = "detail" media-type = "application/xml" url = "http://api.kuangkuang.com/order/1000"/>
</Order>
</Orders>

<Orders>
<Link rel = "list" media-type = "application/xml" url = "http://api.kuangkuang.com/orders"/>
<Order>
<Id> 1000 </id>
<State> waiting review </state>
<Link rel = "detail" media-type = "application/xml" url = "http://api.kuangkuang.com/order/1000"/>
</Order>
</Orders>

Let's check the specific order information. Let's GET: http://api.kuangkuang.com/order/1000. the server returns the following data:


Xml Code
<Order>
<Link rel = "detail" media-type = "application/xml" url = "http://api.kuangkuang.com/order/1000"/>
<Content>
<Id> 1000 </id>
<Cost> 88.0 </cost>
<State> waiting review </state>
<Squence>
<Activity rel = "review" media-type = "application/xml" url = "http://api.kuangkuang.com/review/order/1000"/>
</Squence>
</Content>
</Order>

<Order>
<Link rel = "detail" media-type = "application/xml" url = "http://api.kuangkuang.com/order/1000"/>
<Content>
<Id> 1000 </id>
<Cost> 88.0 </cost>
<State> waiting review </state>
<Squence>
<Activity rel = "review" media-type = "application/xml" url = "http://api.kuangkuang.com/review/order/1000"/>
</Squence>
</Content>
</Order>

Note these two rows:


Java code
<State> waiting review </state>
<Squence>
<Activity rel = "review" media-type = "application/xml" url = "http://api.kuangkuang.com/review/order/1000"/>
</Squence>

<State> waiting review </state>
<Squence>
<Activity rel = "review" media-type = "application/xml" url = "http://api.kuangkuang.com/review/order/1000"/>
</Squence>

This information is added by the workflow, which tells us that the status of the current order is pending for review and that we need to review the next step. Then, let's PUT http://api.kuangkuang.com/review/order/100020.the server has passed the review and the server returns the data:

 


Xml Code
<Order>
<Link rel = "detail" media-type = "application/xml" url = "http://api.kuangkuang.com/order/1000"/>
<Content>
<Id> 1000 </id>
<Cost> 88.0 </cost>
<State> waiting send </state>
<Squence>
<Activity rel = "send" media-type = "application/xml" url = "http://api.kuangkuang.com/sent/order/1000"/>
</Squence>
</Content>
</Order>

<Order>
<Link rel = "detail" media-type = "application/xml" url = "http://api.kuangkuang.com/order/1000"/>
<Content>
<Id> 1000 </id>
<Cost> 88.0 </cost>
<State> waiting send </state>
<Squence>
<Activity rel = "send" media-type = "application/xml" url = "http://api.kuangkuang.com/sent/order/1000"/>
</Squence>
</Content>
</Order>

Similarly, the workflow adds the following two rows of data:


Xml Code
<State> waiting send </state>
<Squence>
<Activity rel = "send" media-type = "application/xml" url = "http://api.kuangkuang.com/sent/order/1000"/>
</Squence>

<State> waiting send </state>
<Squence>
<Activity rel = "send" media-type = "application/xml" url = "http://api.kuangkuang.com/sent/order/1000"/>
</Squence>

The status of the current order is waiting for delivery, and the next step is to complete this step. In this case, if the customer checks the number of his/her orders

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.