Makes an HTTP GET request to a Stanford ExploreCourses API endpoint and returns the response as an XML document. Handles response validation and error cases.
Value
An xml2::xml_document object containing the parsed API response. The structure depends on the specific endpoint called.
Details
The function performs these steps:
Makes HTTP GET request using
httr2
Validates HTTP response status (must be 200)
Converts response body to XML document
Error handling covers:
Network/connection failures
Non-200 HTTP status codes
XML parsing errors
All errors are converted to standardized error messages with endpoint information and original error details.
Rate Limiting
The ExploreCourses API does not currently require authentication or impose rate limits, but considerate usage is recommended.
Response Format
The API returns XML data in the ExploreCourses schema version 20140630. The exact structure varies by endpoint:
Departments: List of schools containing departments
Courses: List of courses with sections and schedules
See also
httr2::request()
for the underlying HTTP request functionalityxml2::read_xml()
for XML parsing
Examples
if (FALSE) { # \dontrun{
# Get departments list
deps_xml <- make_api_request(DEPARTMENTS_ENDPOINT)
# Get courses for CS department
courses_url <- sprintf(COURSE_ENDPOINT, year = "20232024", name = "CS")
cs_xml <- make_api_request(courses_url)
} # }