Should API fetching be frontend or backend? [closed] Should API fetching be frontend or backend? [closed] flask flask

Should API fetching be frontend or backend? [closed]


There are some conditions which require or prefer API fetching to be in the back-end:

  1. When you need to use security credentials to access the API and you those credentials need to stay private.

  2. When the API does not permit cross origin access so your front-end could not directly access it.

  3. When you need to do some processing on the API results and you wish to keep the processing algorithms a trade secret (keep in mind that all processing done in the front-end is available for any coder to see). There are no secrets in the front-end code.

  4. When the front-end device may not have appropriate resources (CPU, memory, etc..) to process the API results. This can particularly be the case with smaller dedicated devices.

  5. When you don't want the front-end device to have to expend the battery energy to regularly access the API. This might particularly be the case if you're regularly polling some API looking for changes. In that case, you might want the back-end to do the polling and just let the front-end know when there is something to actually do.

  6. When there are reasons to do some centralized performance management of your access to the API such as caching of results or request throttling.

  7. When all front-end devices may not have proper network access to the API server.

If there are no compelling benefits to putting the API access in the back-end, then it may be more scalable (for your server) to let the front-end do as much work as it can.