0

I’m working on a medium-sized project. One of the parts has to do with account creation.

I went with a RESTful API design at first, but I’m now having second thought. Persistent data are saved in MongoDB.

So to create an user, one API request is required to the backend. After creating the account, another API call to /units would add the newly created user to the unit. I modeled this process in two steps, the client is not amused.

My first request includes account information, which returns the user id. The second request mutates the unit, and adds the user to the unit.

They want this to be modeled as a wizard, fill the data, click nexts, and done. So essentially, I’m faced with a two options:

  1. Send multiple requests in order, if client receives an error on any of the requests, roll back (manually by sending requests again...)
    1. Create a new route for the purpose

I am just wondering what would one do? The first one sounds horrible; but the second sounds unRRSTful. Anyone else faced this?

  • Is it possible for the accounts to be created and then not assigned to any unit? Are there additional information sent in the second request that could not have been sent in the first request? Maybe in this particular scenario it'd be enough to make a single request and perform those two steps on the back-end side? – kmaczuga Jun 21 '17 at 12:12
  • @kmaczuga details of request added. But wouldn’t mutating two data structure by definition make not RESTful? – Shane Hsu Jun 21 '17 at 14:03
  • Not necessarily. If Unit can not be added independently of the Account, then, is not It a single process?. The wizard can be simulated at client side and then do the rest with a single POST. – Laiv Jun 21 '17 at 20:31
1

Your back end should have knowledge of the wizard steps that are completed and which ones are not, and it should know at what point the user is allowed to start using the system.

For example you can POST to /user/registration/step1 supplying some details, then POST /user/registration/step2 etc. Before completing all the steps the user could also go back in the wizard and repost another step. In the case where the user completes some steps then leaves the site and comes back another day, you can GET /user/registration/step1 etc to repopulate the wizard.

This approach is both RESTful and very practical.

You might also like to consider a design where certain functions within your software require a certain number of wizard steps to have been completed. In this case when the user attempts to perform an action you should remember what they were doing, redirect them to the first incomplete wizard step, and when they have completed enough steps give them the option to return to their original task, or complete all the remaining wizard steps.

This design is a bit complicated to get right, but avoids losing users who can't be bothered to complete all the wizard steps up front.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.