Experience Salesforce

REST API Part 7

What You’ll Learn

  • Explanation Of API Callout Code
  • Remote Site Settings

Explanation Of API Callout Code

An API callout code involves various classes:

  1. HTTP class: This class object we create, to send API requests using send method.
  2. 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.

salesforce-developer
Next Topic

Need Extra Support? Our FREE study materials have got you covered.

Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.

cts-img
Rakshabandhan Sale