A
A
Alexey2019-06-02 18:53:22
CRUD
Alexey, 2019-06-02 18:53:22

How to properly organize relationship creation/update requests based on the JSON API?

Let's say there are "Organizations" and "Contacts" resources. The relationship between resources is many to many.
The user creates a new organization with a couple of contacts. How, based on the current json api standard , how to properly organize requests to the server to create objects?
If I understand correctly, then the sequence should be:
1. POST request with organization attributes;
2. POST requests with attributes of each contact;
3. POST request to the organization relationship resource (/organization/:id/relationships) to associate the organization with the contacts. As an option - a PATCH request to the organization resource indicating the relationship to the recorded contacts.
It is obvious that requests should be fulfilled strictly sequentially. But what if, for example, after saving the organization, a contact validation error occurred on the server? Or if, after saving contacts, the client lost connection, and the relationship was not recorded? Indeed, in this case, the database will contain an organization without contacts, and / or contacts without communication with the organization.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question