Persons in Space

BAIS 462

Author

Patrick Berry

Introduction

The Open Notify API provides real-time data on how many people are currently in space, which can be fascinating for anyone curious about space exploration or human presence beyond Earth. Someone might be interested in this information out of sheer curiosity—just knowing that astronauts are orbiting above us right now can make space feel a little closer and more real. Educators can use it to spark interest in science and technology, while hobbyists and developers can use the data to build fun space-related projects or dashboards. It’s a simple but meaningful way to stay connected to ongoing space missions and human achievements in space travel.

Walk through

One of the great things about the Open Notify API is that it requires no setup on the service’s website—no login, no API key, and no authentication. You can use it instantly by sending a simple HTTP GET request.

In this code chunk, I created a function called count_astronauts() that uses an API from Open Notify to determine how many astronauts are currently in space. The function sends a GET request to the API endpoint and converts the response from JSON format into a readable structure in R. It then accesses the people section of the response, counts the number of rows (which represents the number of astronauts), and returns a sentence stating the result. I included the function call directly in the R Markdown chunk so that the output would be visible when I knit the document and publish it to RPubs. This demonstrates how APIs can be used in R to pull live data and present it in a clean, interpretable format.

Demonstration

count_astronauts <- function() {
  endpoint <- "http://api.open-notify.org/astros.json"
  
  data <- 
    GET(endpoint) %>% 
    content(as = "text", encoding = "UTF-8") %>% 
    fromJSON()
  
  count <- data %>%
    use_series(people) %>%
    nrow()
  
  paste("There are", count, "astronauts in space.")
}

# Print the result to be visible in RPubs
count_astronauts()
[1] "There are 12 astronauts in space."

Conclusion

In this API, I retrieve how many persons there currently are in space. At the time of making this, there are 12 astronauts in space.