[SalesForce] Http Callout to Rest API from apex

How to send request and get response from server when working with Rest API.

Best Answer

 Http http1=new Http();
 HttpRequest req1=new HttpRequest();
 req1.setendpoint('URL');
 req1.Setheader('String','String');
 req1.setmethod('POST'); //you can also SET method `GET` with Get there is no need of req1.setbody()
 req1.setbody(string);
 HttpResponse res1;
 res1 = http1.send(req1);
 String str=res1.getbody();