API Speedrun Any%

The Joke

Why would you want to use this:

You have been invited to the worlds premier stand up comedy festival and you forgot to prep any material so instead you generate all of your jokes using the joke api. Or you are bored and want a joke.

How to set up the api

Step 1: go to the api’s website https://jokeapi.dev/. You will then find that the base url is https://v2.jokeapi.dev/joke/Any

you then want to chose your file format and have that as the format parameter so it returns the file type you want. We will use JSON and you would want it to be in your language which for us is english so we have the lang pramater as en. We also put our api in safe mode because this is a school project meaning that our url becomes. We also only want jokes of type single.

we then have this as our url

jokeUrl <- "https://v2.jokeapi.dev/joke/Any?format=json&lang=en&safe-mode&type=single"

You then run the function and test to make sure the url works. After that you put the joke into a data frame. And you make a function to do that

get_joke <- function() {
return ((jokeUrl %>% 
  GET() %>% 
  content(as = "text",
          encoding = "UTF-8") %>% 
  fromJSON() %>% 
    use_series(joke)))
}

API output

here is an example output

get_joke()
[1] "Two C strings walk into a bar.\nThe bartender asks \"What can I get ya?\"\nThe first string says \"I'll have a gin and tonic.\"\nThe second string thinks for a minute, then says \"I'll take a tequila sunriseJF()#$JF(#)$(@J#()$@#())!*FNIN!OBN134ufh1ui34hf9813f8h8384h981h3984h5F!##@\"\nThe first string apologizes, \"You'll have to excuse my friend, he's not null-terminated.\""