Skip to content

Instantly share code, notes, and snippets.

@lkatney
Last active August 29, 2015 14:15
Show Gist options
  • Save lkatney/c5c1f0712fe064110cb8 to your computer and use it in GitHub Desktop.
Save lkatney/c5c1f0712fe064110cb8 to your computer and use it in GitHub Desktop.
Method to make callouts handling PATCH request
/*********************************************************************************
@description : method to make https callouts
@param : url, method, body , headers
@return : HttpResponse
**********************************************************************************/
public static HttpResponse makeCallout(String url, String method, String body, Map<String,String> headers){
HttpRequest req = new HttpRequest();
HTTPResponse res = new HTTPResponse();
Http http = new Http();
//for patch
if(method == 'PATCH'){
req.setMethod('POST');
url += '?_HttpMethod=PATCH';
}else{
req.setMethod(method);
}
req.setEndpoint(url);
if(String.isNotBlank(body)){
req.setBody(body);
}
if(headers != null){
for(String key : headers.keySet()){
req.setHeader(key, headers.get(key));
}
}
res = http.send(req);
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment