Authentication and named credentials
Most of the APIs that Salesforce developers integrate with require some form of authentication to ensure that the data being retrieved is done so in a way that either enforces security controls on the external platform or enables some form of rate control and limiting.
There are many different authentication mechanisms for external systems; however, the most common are Basic authentication and OAuth. Basic authentication is simply the provision of a username and password in the header of the request, while OAuth covers several different flows within the protocol.
It is outside the scope of this book to dive into how you might implement a full OAuth flow within your application, and I would recommend that you do not do so and instead use a tool such as Named Credentials, which we will discuss shortly. To allow us to see both how and why we may use a named credential, we are going to add a new method to our existing Apex class called getBasicAuth...