A
A
aazon2014-06-30 13:19:55
css
aazon, 2014-06-30 13:19:55

What is the best way to work with related resources through the REST API?

How would you implement the following functionality:
- there is an API of the trading platform, made following the REST approach, that is, users work with resources
- there is an "order comment" entity that matches the "order comment" REST resource.
- there is an entity "order". The "order" resource = the "order" entity + the comments field containing an array of comments to this order
- any change in the order data (status, delivery time, etc.) should add a comment
The seller wants to change the order field, for this you need to perform actions with two resources : update the order field and create a new comment.
Options for how to implement this in the API:
1. Two separate REST calls: PATCH /orders/123 and POST /orders/123/comments. The disadvantage is that there is no guarantee that both calls will be made.
2. One RPC call to POST /order/update which takes the new field value and comment text. Disadvantage - moving away from REST
Have you faced a similar problem?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Karyakin, 2016-03-01
@eellazy

If you want several buttons, hang the event on the class, not on the id. For example:

<input type="button" value="Заказать" class="popup__toggle" />

F
frontender, 2016-03-01
@frontender

id must be unique. only one id is triggered, which is the first one. Put a handler on a class

P
Pavel Solovyov, 2014-06-30
@pavel_salauyou

One RPC call to POST /order/update which takes the new field value and comment text. Disadvantage - we are moving away from REST - why are we moving away from REST?

K
Kroz, 2014-09-02
@Kroz

In my opinion, there is a mixture of resources here. You want to interact atomically with multiple resources at once, which HTTP doesn't allow you to do.
I would think, why do you even need comments in this case? To describe the change?
In our case, a similar task would be solved through versioning the order object + a field with a comment on the last change in it. That is, a resource is an order along with a description of the last change. This is similar to making changes to a wiki page in many engines, where you can enter a description of what was changed and why.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question