API - Give Food - No key - R code
# Install packages httr and jsonlite
```{r} install.packages("httr") install.packages("jsonlite") ``` # Create a GET response to call the API ```{r} foodbank <- httr::GET("https://www.givefood.org.uk/api/2/foodbanks/") # View API GET response result str(foodbank) # View the main source of the data needed from the API - Normally content str(foodbank$content) ``` # Convert the raw content to text (in this case, a JSON string) ```{r} foodbankcontent <- httr::content(foodbank, as = "text") # View JSON String result str(foodbankcontent) ``` # Convert the JSON string to a dataframe and view data in a table ```{r} foodbankJSON <- jsonlite::fromJSON(foodbankcontent) View(foodbankJSON) ```
Comments
Post a Comment