Skip to content

A ☁️ Salesforce Apex ApiController for all your integration usages

Notifications You must be signed in to change notification settings

Stretch-Engage/ApiController

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to use the ApiController class

ApiController is a wrapper class for handling all integrations using the HttpRequest and HttpResponse classes in Apex. This simple guide explains how to use the class in your Apex code.

Prerequisites

Before using the ApiController, you need to ensure that:

  • You have created a named credential to authenticate the API callout.

Deployment

You can use the quick installer here to deploy directly to your org.

Deploy to salesforce

After install assign the permission set View and manage Gantt Chart to relevant users.

Usage

To use the ApiController class, follow these steps:

  1. Create an instance of the class:
ApiController apiController = new ApiController();
  1. Initialize the controller with a named credential and a path:
apiController.init('named_credential', ApiController.HttpVerb.GET, '/path/to/resource');

Note that you need to specify the HttpVerb enum value to determine the HTTP method for the API callout.

  1. Set additional parameters and add headers if necessary:
apiController.setTimeout(5000);
apiController.addHeader('Content-Type', 'application/json');
  1. Add query parameters and a request body if necessary:
Map<String, String> queryParams = new Map<String, String>{
    'param1' => 'value1',
    'param2' => 'value2'
};
apiController.addQueryParameter(queryParams);

String requestBody = '{"key": "value"}';
apiController.addBody(requestBody);
  1. Perform the API callout:
apiController.doCallout();
  1. Retrieve the response from the controller:
HttpResponse response = apiController.getResponse();

About

A ☁️ Salesforce Apex ApiController for all your integration usages

Topics

Resources

Stars

Watchers

Forks

Languages