Nobelprize.org
Lists of Nobel Prizes and Laureates

API Examples

 

PHP

Below is a simple example of php code that uses curl to retrieve data from the API in order to list the Nobel Laureates in Physiology or Medicine between 1990 and 1994. For simplicity, it's kept short and has no error handling.

The php code:


<?php

# Base URL for the API
$url  'http://api.nobelprize.org/v1/prize.json';
# List Nobel Prizes in Medicine from 1990 to 1994
$url .= '?category=medicine&year=1990&yearto=1994';

# Retreieve the result from the API using CURL
$ch curl_init();
curl_setopt($chCURLOPT_URL,$url);
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
$string curl_exec($ch);
curl_close($ch);

# Read the JSON output into an associative array
$result  json_decode($stringtrue);

# Find out how many years that are listed
$numyears count($result['prizes']);

for (
$i 0$i $numyears$i++) {

# Print out the category and year
  
$cat $result['prizes'][$i]['category'];
  
$year $result['prizes'][$i]['year'];
  print 
"<b>$cat $year</b><br>\n";

# Find out how many laureates this category and year
  
$numlaur count($result['prizes'][$i]['laureates']);

  for (
$j 0$j $numlaur$j++) {

#   Print out the names
    
$firstname $result['prizes'][$i]['laureates'][$j]['firstname'];
    
$surname $result['prizes'][$i]['laureates'][$j]['surname'];
    print 
"$firstname $surname <br>\n";

  }
  print 
"<br>\n";
}

?>

 

The result:

medicine 1994
Alfred G. Gilman
Martin Rodbell

medicine 1993
Richard J. Roberts
Phillip A. Sharp

medicine 1992
Edmond H. Fischer
Edwin G. Krebs

medicine 1991
Erwin Neher
Bert Sakmann

medicine 1990
Joseph E. Murray
E. Donnall Thomas

 

 

The open data project at Nobelprize.org was supported in 2012 by Vinnova.

 

Share this:
To cite this page
MLA style: "API Examples". Nobelprize.org. Nobel Media AB 2014. Web. 28 Jul 2014. <http://www.nobelprize.org/nobel_organizations/nobelmedia/nobelprize_org/developer/api-example.html>

Recommended:

On 27 November 1895 Alfred Nobel signed his last will in Paris.

 

Try to save some patients and learn about human blood types!

 

Discover the 2012 awarded research on stem cells and cell signalling.