{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Code Examples","type":"basic","slug":"code-examples","excerpt":"Below are some code examples for the Nobel Prizes API","body":"[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n# Base URL for the API\\n$url  = 'http://api.nobelprize.org/v1/prize.json';\\n# List Nobel Prizes in Medicine from 1990 to 1994\\n$url .= '?category=medicine&year=1990&yearto=1994';\\n\\n# Retreieve the result from the API using CURL\\n$ch = curl_init();\\ncurl_setopt($ch, CURLOPT_URL,$url);\\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);\\n$string = curl_exec($ch);\\ncurl_close($ch);\\n\\n# Read the JSON output into an associative array\\n$result  = json_decode($string, true);\\n\\n# Find out how many years that are listed\\n$numyears = count($result['prizes']);\\n\\nfor ($i = 0; $i < $numyears; $i++) {\\n\\n# Print out the category and year\\n  $cat = $result['prizes'][$i]['category'];\\n  $year = $result['prizes'][$i]['year'];\\n  print \\\"<b>$cat $year</b><br>\\\\n\\\";\\n\\n# Find out how many laureates this category and year\\n  $numlaur = count($result['prizes'][$i]['laureates']);\\n\\n  for ($j = 0; $j < $numlaur; $j++) {\\n\\n#   Print out the names\\n    $firstname = $result['prizes'][$i]['laureates'][$j]['firstname'];\\n    $surname = $result['prizes'][$i]['laureates'][$j]['surname'];\\n    print \\\"$firstname $surname <br>\\\\n\\\";\\n\\n  }\\n  print \\\"<br>\\\\n\\\";\\n}\\n\\n?>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]","updates":["5d7c75c589d1d50060985957"],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"55369c446fd3c40d00334964","project":"55369b3b6a63520d00ae6165","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["55369b3c6a63520d00ae6169"],"_id":"55369b3b6a63520d00ae6168","createdAt":"2015-04-21T18:47:23.692Z","releaseDate":"2015-04-21T18:47:23.692Z","__v":1,"project":"55369b3b6a63520d00ae6165"},"__v":1,"createdAt":"2015-04-21T18:51:48.554Z","githubsync":"","user":"55156c1dbc466623002afea2","category":{"sync":{"isSync":false,"url":""},"pages":["55369b3c6a63520d00ae616b","55369c446fd3c40d00334964","55369cb24c3edb0d00877c82","5536a68d6a63520d00ae6177","5536a8ff245c930d007ed937"],"title":"Documentation","slug":"documentation","order":0,"from_sync":false,"reference":false,"_id":"55369b3c6a63520d00ae6169","version":"55369b3b6a63520d00ae6168","createdAt":"2015-04-21T18:47:24.200Z","project":"55369b3b6a63520d00ae6165","__v":5}}

Code Examples

Below are some code examples for the Nobel Prizes API

[block:code] { "codes": [ { "code": "<?php\n\n# Base URL for the API\n$url = 'http://api.nobelprize.org/v1/prize.json';\n# List Nobel Prizes in Medicine from 1990 to 1994\n$url .= '?category=medicine&year=1990&yearto=1994';\n\n# Retreieve the result from the API using CURL\n$ch = curl_init();\ncurl_setopt($ch, CURLOPT_URL,$url);\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);\n$string = curl_exec($ch);\ncurl_close($ch);\n\n# Read the JSON output into an associative array\n$result = json_decode($string, true);\n\n# Find out how many years that are listed\n$numyears = count($result['prizes']);\n\nfor ($i = 0; $i < $numyears; $i++) {\n\n# Print out the category and year\n $cat = $result['prizes'][$i]['category'];\n $year = $result['prizes'][$i]['year'];\n print \"<b>$cat $year</b><br>\\n\";\n\n# Find out how many laureates this category and year\n $numlaur = count($result['prizes'][$i]['laureates']);\n\n for ($j = 0; $j < $numlaur; $j++) {\n\n# Print out the names\n $firstname = $result['prizes'][$i]['laureates'][$j]['firstname'];\n $surname = $result['prizes'][$i]['laureates'][$j]['surname'];\n print \"$firstname $surname <br>\\n\";\n\n }\n print \"<br>\\n\";\n}\n\n?>", "language": "php" } ] } [/block]