Consuming APIs
Retrieving data or communicating with other systems via APIs is a common requirement in web development and, therefore SPFx solutions. In JavaScript in general, any API can be called using the tool-agnostic fetch() API (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) implemented by all modern browsers.
However, most of the time, SPFx components will get data directly from SharePoint (for example, a list or a site using the SharePoint REST API) or the Microsoft 365 ecosystem (for example, Teams, Outlook, and so on using the Microsoft Graph API). Because this data is protected and always retrieved on behalf of the currently logged-in user, these API calls require an additional authentication layer to work.
Although the standard fetch() API could be used in SPFx solutions, dealing with this authentication process manually, or specificities of each API in the context of SPFx, can be quite cumbersome. That is why SPFx provides a set of utility...