Last active
August 29, 2015 14:15
-
-
Save lkatney/c5c1f0712fe064110cb8 to your computer and use it in GitHub Desktop.
Method to make callouts handling PATCH request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************************* | |
@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