In PHP, you might have something like this:
// EDIT: only need to use urlencode() on user supplied variables //$url = urlencode("http://xyz.com/api?apikey=foo&v1=bar&v2=baz"); $url = "http://xyz.com/api?apikey=foo&v1=bar&v2=baz"; $response = file_get_contents($url);
$response will contain the string of any xyz.com that is displayed when accessing $url (this is what you will see if you visited $url directly).
The next task should be to parse $response based on its data structure (e.g. XML, JSON, etc.) so that it can be used by the rest of your code.
There are several PHP libraries for parsing XML or JSON. Personally, I prefer to use SimpleXMLElement and json_decode() , which is included in PHP 5> = 5.2.0.
Depending on the API, it will probably send you some kind of error / response code structure if it does not understand the $url request, which you could check after analyzing the response.
If $response returns false, then, as a rule, some error related to $url occurred.
I found that an intuitive way to think about these XHR requests is that you pass the arguments ( GET parameters) to the function (API URL). And the response from the API URL is similar to the return statement from a function.
UPDATE:
An example API for Groupon suggested by OP in the comments:
$apikey = "client_id=abcd1234567890"; $division = "division_id=chicago"; $url = "http://api.groupon.com/v2/deals?" . implode("&", array($apikey, $division)); $response = file_get_contents($url); $deals = json_decode($response, true); foreach($deals['deals'] as $deal){ $format = 'Deal: <a href="%s">%s</a><br/>'; echo sprintf( $format, $deal['dealURL'], $deal['announcementTitle']); }
The above code will print a list of all transaction names and URLs for the Chicago area. If you look at the Sample JSON Response sections on the Groupon API page, this will give you the whole data structure that will be mapped to the $deals associative array.
If any of the GET API parameters is provided by the user (for example, from a web form), you will want to do something like $division = "division_id=" . urlencode($user_input); $division = "division_id=" . urlencode($user_input); .