<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/interfacing-with-apis-using-r-the-basics/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/06/interfacing-with-apis.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>While R (and its package ecosystem) provides a wealth of functions for querying and analyzing data, in our cloud-enabled world there's now a plethora of online services with APIs you can use to augment R's capabilities. Many of these APIs use a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Representational_state_transfer" target="_blank">RESTful interface</a>, which means you will typically send/receive data encoded in the JSON format using HTTP commands.</p>
<p>Fortunately, as Steph Locke explains in her most recent <a rel="nofollow" href="https://itsalocke.com/microsoft-cognitive-services-text-analytics-api/" target="_blank">R Quick tip</a>, the process is pretty simple using R:</p>
<ol>
<li>Obtain an authentication key for using the service </li>
<li>Find the URL of the API service you wish to use</li>
<li>Convert your input data to JSON format using <a rel="nofollow" href="https://www.rdocumentation.org/packages/jsonlite/versions/1.5/topics/toJSON%2C%20fromJSON?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">toJSON</a> in the <a rel="nofollow" href="https://mran.microsoft.com/package/jsonlite/" target="_blank">jsonlite package</a></li>
<li>Send your data to the API service using the <a rel="nofollow" href="https://www.rdocumentation.org/packages/httr/versions/1.2.1/topics/POST?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">POST</a> function in the <a rel="nofollow" href="https://mran.microsoft.com/package/httr/" target="_blank">httr package</a>. Include your API key using the <a rel="nofollow" href="https://www.rdocumentation.org/packages/httr/versions/1.2.1/topics/add_headers?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">add_headers</a> function</li>
<li>Extract your results from the API response using the <a rel="nofollow" href="https://www.rdocumentation.org/packages/jsonlite/versions/1.5/topics/toJSON%2C%20fromJSON?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">fromJSON</a> function</li>
</ol>
<p>Steph provides an example of detecting text language using the Microsoft Cognitive Services <a rel="nofollow" href="https://itsalocke.com/microsoft-cognitive-services-text-analytics-api/" target="_blank">Text Analytics API</a>, but that basic recipe should work for most APIs. (API keys <a rel="nofollow" href="https://azure.microsoft.com/en-us/try/cognitive-services/" target="_blank">for other Microsoft Cognitive Services APIs</a> for vision, speech, language, knowledge and search are also available for free use with your Github account.) There many APIs available for use around the web, and this <a rel="nofollow" href="https://github.com/abhishekbanthia/Public-APIs" target="_blank">list of public APIs</a> maintained by Abhishek Banthia is also a useful resource.</p>
<p>Locke Data: <a rel="nofollow" href="https://github.com/abhishekbanthia/Public-APIs" target="_blank">R Quick tip: Microsoft Cognitive Services’ Text Analytics API</a></p>
<p> </p>
<p> </p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2017/06/interfacing-with-apis.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...

	<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/6_QakDNnFi4" height="1"></a></div>