The HttpHelper function helps you with HTTP calls covering CRUD operations.

To get an instance of the IHttpHelper, you must call GetHttpHelper(), which returns you an instance of IHttpHelper allowing you to call the following methods:

It is not recommended to call salesforce API from Custom Code, due to performance reasons.

Methods

HttpContent GetHttpContenFromtXml<T>(T payload);
Task<T> GetAsync<T>(string requestUri);
Task<HttpResponseMessage> GetAsync(string requestUri);
Task<T> PostAsync<T>(string requestUri, HttpContent content);
Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content);
Task<T> PutAsync<T>(string requestUri, HttpContent content);
Task<HttpResponseMessage> PutAsync(string requestUri, HttpContent content);
Task<HttpResponseMessage> DeleteAsync(string requestUri);
CODE

Example: Invoke GET API call

var httpHelper = GetHttpHelper();
var logHelper = GetLogHelper();

string url = "https://jsonplaceholder.typicode.com/todos/1";
var response = await httpHelper.GetAsync<SampleResponse>(url);
logHelper.LogDebug(response);
CODE

Console Output

Complete-GetAsync(https://jsonplaceholder.typicode.com/todos/1), HttpStatus=OK, Time=285.534
{"userId":1,"id":1,"title":"delectus aut autem","completed":false}
CODE

Example: Invoke POST API call

var httpHelper = GetHttpHelper();
var logHelper = GetLogHelper();

string url = "https://jsonplaceholder.typicode.com/todos/1";
var response = await httpHelper.GetAsync<SampleResponse>(url);

url = "https://jsonplaceholder.typicode.com/todos";
response.id = 0;
response.title = "Callback";
var contentToPost = new StringContent(JsonConvert.SerializeObject(response),Encoding.UTF8,"application/json");
var postResult = await httpHelper.PostAsync<SampleResponse>(url,contentToPost);
logHelper.LogDebug(postResult);
CODE

Console Output

Complete-GetAsync(https://jsonplaceholder.typicode.com/todos/1), HttpStatus=OK, Time=285.534
{"userId":1,"id":1,"title":"delectus aut autem","completed":false}
Complete-PostAsync(https://jsonplaceholder.typicode.com/todos), HttpStatus=Created, Time=400.073
{"userId":1,"id":201,"title":"Callback","completed":false}
CODE