spacer
spacer
Table of Contents

PHP cURL

For REST services the PHP cURL library can be used to access the service.

HTTP GET

For services available through a HTTP GET request, for example WSDbfetch:

// Base URL for the service
$baseUrl = 'http://www.ebi.ac.uk/Tools/webservices/rest/dbfetch';
// Parameters for call
$params = array('db' => 'UNIPROT',
		'id' => 'ADH1A_HUMAN',
		'format' => 'fasta'
		);
// Build URL
$url = "$baseUrl/" . $params['db'] . '/' . $params['id'];
if(array_key_exists('format', $params)) $url .= '/' . $params['format'];
// Get entry using cURL
$curl = curl_init() or die(curl_error());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);
curl_close($curl);
// Print result
echo $result;

HTTP POST

For services which require the use of a HTTP POST request, for example WSInterProScan (see REST tutorial):

// Base URL for the service
$baseUrl = 'http://www.ebi.ac.uk/Tools/webservices/rest/';
// Tool name
$toolName = 'iprscan';
 
// Parameters for call
$params = array(
		'tool' => 'iprscan',
		'srchType' => 'interactive',
		'email' => 'your@email',
		'seqtype' => 'P',
		'crc' => TRUE,
		'sequence' => 'uniprot:slpi_human'
		);
 
// Create a cURL session
$curl = curl_init() or die(curl_error());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
 
// Submit job
$submitUrl = "$baseUrl/submit";
curl_setopt($curl, CURLOPT_URL, $submitUrl);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$jobId = curl_exec($curl);
// Print job identifier
echo "$jobId\n";
 
// Close the cURL session
curl_close($curl);

Examples

 
tutorials/06_programming/php/rest/curl.txt · Last modified: 2010/02/09 20:58 by hpm
spacer
spacer