I hope I've chosen the right community for that (there's no software architecture / design one)!
I'd like to ask you about practical considerations of RESTful APIs (and similar design patterns as for that matter) in context of complex server-side operations / business logic.
Few things to keep in mind:
- I know REST is not the only way to go nor the silver bullet
- I couldn't find any design pattern / practice that would let me keep the API structured (like REST does) and make it sensible for what I need to do.
I think it's going to be much easier if I give you an example, so here we go: I'm facing a business logic that spans multiple steps. The steps are:
- User make various choices and submit them (let's say they are using HTML form).
- These choices are validated for being both up-to-date (with database state, e.g. some options may no longer be available at the time they are submitted) and against themselves (because you can only have certain combinations of options put together).
- If everything is fine, some database updates are made (e.g. to create a pre-order of limited goods for that user).
- User is then given the response (let it be HTML form for now) containing information that let them complete another step by making even more choices - let's say they should pick their method of payment for previously pre-ordered goods.
- They submit their choices again, in response they receive information that will let them complete their payment.
- And here it starts to get ugly...
While up to point 5 I am able to identify REST resources, etc. It gets really hard to process further steps. Why? Because once the user completes the payment (one way or another, doesn't matter), they will receive URL of my API endpoint that should verify the payment, process the pre-order into the actual order and return confirmation to the user. Which in case of REST should be (the confirmation) a resource. This is fine, but having in mind the process of turning pre-order into an order means creating multiple resources of different types, it means we "hide" these resources from the user.
Basically, there's a lot of things going on under the hood and they should probably be returned in a confirmation. The problem is, there's no confirmation anywhere in the database.
But well, let's get to the question - is there any design pattern, framework, architecture more suitable to that kind of problems?
Sidenotes:
- I said there's no confirmation in the database - I have a monolithic app that I'd like to turn into API-based application to decouple back-end and front-end.
- I'm also concerned about performance. I believe this could be ultimately done the RESTful way (although may be hard without keeping the state), but that would mean making the simple API for complex problem, resulting in a lot of API calls to achieve the same effect.
EDIT
Another thing that concerns me and make me go against RESTful API is that it would require these multiple API calls to complete the whole process acting on resources, which would mean any client app utilizing this API would have to re-implement the same logic as opposed to encapsulating this logic on server-side
"let's get to the question"
. But basically the question is whether REST is suitable for such problems, despite the overhead and "hiding" lots of resources from user or is there a better pattern for complex APIs?