{"id":3436,"date":"2021-03-07T22:43:31","date_gmt":"2021-03-07T21:43:31","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3436"},"modified":"2021-03-07T22:43:31","modified_gmt":"2021-03-07T21:43:31","slug":"getting-data-from-an-api","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3436","title":{"rendered":"Getting data from an API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Once an API is running, we may start a client. This client fires a call. This call is fired with &#8220;requests.get&#8221;. Between the brackets, we see a call that could be run from any webbrowser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reponse can then be received with response.json()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The json is very similar to a dataframe. The dataframe can then be set up by reading a row in the json and appending the row to the dataframe.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import requests\nimport pandas as pd\ndoel = []\ndf = pd.DataFrame(doel, columns=[\"Author\", \"FirstLine\", \"Index\", \"Year\", \"Title\"])\nresponse = requests.get(\"http:\/\/127.0.0.1:5000\/api\/v1\/resources\/books\/all\")\nif (response.status_code == 200):\n  print('Status code: ',response.status_code)\n  data = response.json()\n  for i in range(len(data)):\n    rij = data[i]\n    df = df.append([[]])\n    df.iloc[i] = rij\nelif (response.status_code == 404) :\n  print(\"Result not found!\")\n  print('Nmbr rows: ',df.shape[0],' Nmbr columns: ',df.shape[1])<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Once an API is running, we may start a client. This client fires a call. This call is fired with &#8220;requests.get&#8221;. Between the brackets, we see a call that could be run from any webbrowser. The reponse can then be received with response.json() The json is very similar to a dataframe. The dataframe can then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3436","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3436"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3436\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3436"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}