Search code examples
restapi-designrestful-url

RESTful Domain Application Protocol for an order


I'm working a little project. This is the first time I'm using a restful service. I'm creating a webshop and an app which are using a restful service. I created a DAP for ordering clothes in the webshop.

DAP: enter image description here

State transitions in het DAP:

enter image description here

I want to know if I made a correct DAP, if the URI Tunnelling is correct and if the state transitions are right.

Thankyou for your help!

Edit: the first POST must be /order not order/1


Solution

  • The problem most people make when starting out with restful services is thinking that everything applies to one resource, in your case order.

    In fact you are working with 3 resources, orders, payments and deliveries - when you realize this then your options suddenly expand.

    Now you could do something like this:

    POST /order  (creates order, returns Order Id)
    POST /order/{OrderId}/cancel (updates order to cancelled **)
    POST /order/{OrderId}/payments (creates a payment for Order, returns Payment Id ***)
    POST /payments/{PaymentId}/deliveries (creates a delivery for a Payment, returns Delivery Id ***)
    

    ** This is a debatable point in RESTful design, could be a PUT as well, the choice is ultimately yours. there is a ton of discussions on the topic
    *** This makes sense because you would only create a Payment or Delivery in relation to another resource

    Then you could access or modify the additional resources as such:

    GET /payments
    GET /payments/{PaymentId}
    DELETE /payments/{PaymentId}
    PUT /payments/{PaymentId}
    
    GET /deliveries
    GET /deliveries/{DeliveryId}
    DELETE /deliveries/{DeliveryId}
    PUT /deliveries/{DeliveryId}
    

    Hope this gives you some more ideas.