Explanation Of API Callout Code
An API callout code involves various classes:
- HTTP class: This class object we create, to send API requests using send method.
- HTTPRequest Class: This class object we create to set various request-related information using various methods:
- setHeader(key, value): Used to set headers like authorization code, content type, etc.
- setBody(str): Used to set information we want to send in the post method.
- setMethod(methodName): Used to set the HTTP method(‘GET’, ‘POST’, ‘PUT’, ‘PATCH’, or ‘DELETE’, which we are using to call API.
Remote Site Settings
Whenever we call an external API through the Visualforce page, custom button, Javascript code, or directly through Apex callout, we first need to add that API endpoint to Remote Site Settings.
Remote Site Setting is used to avoid accessing malicious websites from Salesforce.com. You can find Remote Site Settings in Setup.