Rest – Too many REST API calls on a page

apiasyncrest

A web app designed with highly modular, small components (in this case using AngularJS directives but could just as easily be WebComponents, ReactJS components, or any other technology). Components often have asynchronous REST API calls, upon initialization or upon user interaction. This design is causing many API calls per page (sometimes 20+). Is there any problem with this design? Some are suggesting we condense the API calls into larger client-side services that act as singletons. So 10 API calls may be reduced to 1, even though a page may only use a portion of that data. Are there any red flags, or problems with this design? Which should be preferred?

Best Answer

This design is causing many API calls per page (sometimes 20+). Is there any problem with this design?

There shouldn't be. The fact that each request is small and async means you can greatly speed up your web app, rather than having to wait for a single large request to complete which blocks everything.

Just make sure your javascript is properly asynconious and can do things while your other requests are waiting and you will end up with a much better app than if you had one massive request that fetched everything.

After all browsers are designed to handle loading of many URLs in tandem, even a typical standard webpage may have tens if not hundreds of requests to images, css, javascript, iframes etc etc