I am working on an App which basically communicate with a third party API, it has no back-end. The front-end will be a SPA. Here is the overall scenario:
- The external API needs current user's Id to respond to the requested query.
- My server initially has the user information which it can use to query the API and get the desired result.
- Based on the initial response the user fills in some more detail and requests the API again for the final response.
Possible solutions in my mind:
Solution 1(with additional requests overhead):
- On first request serve the home page to the user, then let the front-end send a request(with the logged in user info) to my server to get initial data from the external API.
- Now, my server requests the external API, gets the response and sends that response to the client.
- Client gets the response, makes another request based on the response.
- Repeat step 2 with the additional data.
Solution 2:
- Since the server already has the user info(using oauth2), let it request the API first then render the landing page with the response loaded in the page as a static global JSON data, let the front-end code to query the static data and use it construct the next request.
- Now, we have the same scenario of step 2 mentioned above.
PS: The API communicates via SOAP protocol and maintains a session using oauth2.
Question: Which scenario is better with respect to error handling and availability? How should I handle the case when the API is down?