Reputation: 174
i am currently developing a web application in which the user should have the possibility to register. For this I have built a VueJS web application and a Golang REST API.
However, the backend is now to be extended so that certain default values are to be set for the user. These default values relate to a different table, i.e. not the table in which the user is saved but a table in which the user-specific settings are stored. I am now wondering at what point this would be optimal from an architectural point of view or whether a good procedure has already been established for this.
Does it make sense to send 2 requests from the client to the backend? One for registration and one for the user-specific settings? Or should the user controller that was specified to create the user be extended so that it also sets the default values for the settings?
Upvotes: -1
Views: 33
Reputation: 5420
Use a single request.
If you use two they are not linked as a transaction. You want both to succeed or both to fail. Also there are dependencies - the user-specific settings will almost certainly be foreign keyed to the user record.
Put the inserts to both tables into a single service method that is wrapped in a single transaction.
Upvotes: 1