What is the correct way to create REST web services?

I have the following state machine, and I want this:

  • create a new order
  • add elements to it (list is optional)
  • confirm the order, causing completion
  • pay for it
  • send him

And this thread is controlled through the REST web service, and I'm not sure which method follows REST principles better.

enter image description here

I came up with two possibilities (the numbers below correspond to the numbers above):

first operation - set by

1. 
POST /create HTTP/1.1

2. 
POST /addItem HTTP/1.1
<data>
    <itemId>123</itemId>
</data>

GET /listItems HTTP/1.1

3.
POST /finish HTTP/1.1

4. 
POST /pay HTTP/1.1
<data>
    <price>123</price>
</data>

5. 
POST /send HTTP/1.1    

second operation - set in the body

1. 
POST / HTTP/1.1
<data>
    <operation>create.new.order</operation>
</data>
- returns resId

2. 
PUT /{resId} HTTP/1.1
<data>
    <itemId>123</itemId>
</data>

GET /items HTTP/1.1

3.
PUT /{resId} HTTP/1.1
<data>
    <operation>finish.order</operation>
</data>

4. 
PUT /{resId} HTTP/1.1
<data>
    <price>123</price>
    <operation>pay.order</operation>
</data>

5. 
PUT /{resId} HTTP/1.1    
<data>
    <operation>send.order</operation>
</data>

The second solution seems better, but I don’t know if I can indicate the operation in the request body - is this normal or not?

Also, I am not sure whether to use PUTeither POSTin 3and 5in the second solution, because I really do not update the resource, I just change the state of the state machine.

, ?

+3
1

:

POST/orders

201 Created, Content-Location, URL- , - /orders/2876276

ok, :

POST/orders/2876276

url, , .

GET/orders/2876276

... . , , json, xml - . , . , , ..

, FINISH , , POST . POST GET , , "".

, POST . , . , , - , , /accounts/39839. .

, POST URL- , . GET , .

"" HTTP-, . - , , . , - /orders/872872872, . GET , , , , .


PUT. PUT , . . (, ..) . . PUT .

PUT , . , , . POST , /items/29829 URL- . PUT , , - /items/29829/mainImage - . PUT , URL- , PUT-ting.


:

, - ?

HTTP . "order" . HTTP- . POST . "" , . .


.

+3

All Articles