What's the preferred url to add an object that is not an aggregated root?

Example: the Order object (aggregate root) has a collection of OrderLine objects (child entities). What url adds the OrderLine to the order? Consider the difference between using an aggregate root controller and having a separate controller for the child.

1: http://example.com/orders/add-orderline?order-id=42&product-id=12&quantity=2

or

2: http://example.com/order-lines/add?order-id=42&product-id=12&quantity=2

Thank!

0


source to share


2 answers


Follow your domain model.

Does the Orderline object exist and can actions be taken on it? (Not an object in code, an object in real life according to the domain.) Most likely not, or it will be a common root.

The Order object exists and you are adding an Orderline to it. So the root object is an Order, with the action of adding an Orderline.



Your url route will follow it, with a controller for the object and an action to add an order line.

From your examples, this is what follows this logic:

http://example.com/orders/add-orderline?order-id=42&product-id=12&quantity=2

      

+1


source


Can an order line exist independently of an order? Therefore, perhaps I would not take action on the order controller.

I would prefer the following:

http://example.com/orders/addline?order-id=42&product-id=12&quantity=2

      



or even addproduct

if the product can only exist on one line in order.

Presumably this would provide a view of the entire order of success, which is another reason it is present on the order controller.

+1


source







All Articles