I’m working on my web service and I have two endpoints: one for user information and another for server-calculated data. When my website is live, I want to show both users and data on the same page. I’m using React.js, but I’m still learning. In the examples I’ve seen, it seems like there’s always just one API call. Is it acceptable to make two API calls to get users and data from both endpoints? If that’s not the right way, what should I do instead?
totally agree, silvia! making 2 api calls is super common in react. just remember to manage loading states so it’s clear what’s happening for the user. i’ve had great luck with useEffect for handling these kinds of things!
Making two API requests is perfectly acceptable and often necessary in practical applications. In my experience with React, I’ve successfully implemented this strategy in several projects where data from multiple sources needed to be displayed on a single page. The critical aspect is to manage loading states and handle errors appropriately for each API call. If both requests are independent, consider using Promise.all() to fetch them simultaneously. Alternatively, if one request can load results while waiting for the other, handle them separately. Also, be sure to implement error boundaries for each request, allowing your application to remain functional even if one request fails.
Hey silvia! nothing wrong with two separate api calls - that’s totally normal. quick question though: are you running them at the same time or does one need the other’s data first? and what’s your take on ux - fine if one loads before the other, or do you need everything together?