Apex library for HTTP callouts
The library was designed for ease of use. Depending on the authentication scheme used by the destination endpoint, it's as easy as picking the appropiate provider:
String basicUser = "myuser"
String basicPassword = "12345"
String endpoint = "https://website.com/api/v1/endpoint1"
BasicProvider provider = new BasicProvider(basicUser, basicPassword)
HttpClient client = new HttpClient(provider);
HttpResponse res = client.post(endpoint, "{\"data\": \"something\"}")
String authEndpoint = "https://website.com/api/v1/auth"
String endpoint = "https://website.com/api/v1/endpoint2"
Map<String, String> authParameters = new Map<String, String>{
'clientId' => 'clientId_value',
'clientSecret' => 'clientSecret_value'
};
OAuthProvider provider = new OAuthProvider(authUrl, authParameters);
HttpClient client = new HttpClient(provider);
HttpResponse res = client.get(endpoint);