lundi 20 février 2017

Converting resources in a RESTful manner

I'm currently stuck with designing my endpoints in a way so that they are conform with the REST principles but also ensure the integrity of the underlying data.

I have two resources, ShadowUser and RealUser whereas the first one only has a first name, last name and an e-mail. The second user has much more properties such like an Id under which the real user can be addressed at other place in the system.

My use-case it to convert specific ShadowUsers into real users.

In my head the flow seems pretty simple:

  • get the shadow users /GET api/ShadowUsers?somePropery=someValue
  • create new real users with the data fetched /POST api/RealUsers
  • delete the shadow-users /DELETE api/ShadowUSers?somePropery=someValue

But what happens when there is a problem between the creation of new users and the deletion of the shadow ones? The data would now be inconsistent. The example is even easier when there is only one single user, but the issue stays the same as there could be something between step 2 and 3 leaving the user existing as shadow and real.

So the question is, how this can be done in a "transactional" manner where anything is good and persisted or something went wrong and nothing has been changed in the underlying data-store?

Are there any "best practices" or "design-patterns" which can be used?

Aucun commentaire:

Enregistrer un commentaire