Skip to contents

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.

Usage

make_api_request(url)

Arguments

url

Character string. Complete URL for the ExploreCourses API endpoint. Expected to be one of:

  • Departments endpoint: DEPARTMENTS_ENDPOINT

  • Course search endpoint: COURSE_ENDPOINT with parameters

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:

  1. Makes HTTP GET request using httr2

  2. Validates HTTP response status (must be 200)

  3. 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

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)
} # }