dracor_api: Send a GET request to DraCor API and parse the results

View source: R/core.R

dracor_apiR Documentation

Send a GET request to DraCor API and parse the results

Description

Function dracor_api() sends a GET request to DraCor API with a specified expected type and parses results depending on selected expected type.

Usage

dracor_api(
  request,
  expected_type = c("application/json", "application/xml", "text/csv", "text/plain"),
  parse = TRUE,
  default_type = FALSE,
  split_text = TRUE,
  as_tibble = TRUE,
  ...
)

Arguments

request

Character, valid GET request.

expected_type

Character, 'MIME' type: one of "application/json", "application/xml", "text/csv", "text/plain".

parse

Logical, if TRUE (default value), then a response is parsed depending on expected_type. See details below.

default_type

Logical, if TRUE, default response data type is returned. Therefore, a response is not parsed and parse is ignored. The default value is FALSE.

split_text

Logical, if TRUE, plain text lines are read as different values in a vector instead of returning one character value. Default value is TRUE.

as_tibble

Logical, if TRUE, data frame will be returned as a tidyverse tibble (tbl_df). The default value is TRUE.

...

Other arguments passed to a parser function.

Details

There are four different 'MIME' types (aka internet media type) that can be retrieved for DraCor API, the specific combination of possible 'MIME' types depends on API command. When parse = TRUE is used, the content is parsed depending on selected 'MIME' type in expected_type:

application/json

jsonlite::fromJSON()

application/xml

xml2::read_xml()

text/csv

data.table::fread()

text/plain

No need for additional preprocessing

If 'DraCor' API is not available (no internet connection, the server is down or does not respond within the time limits, see below), returns an error status or data that cannot be parsed, dracor_api() does not throw an error: it shows an informative message and returns NULL invisibly. All functions of the package that request data from 'DraCor' API behave the same way.

Value

A content of a response to GET method to the 'DraCor' API. If parse = FALSE or default_type = TRUE, a single character value is returned. Otherwise, the resulting value is parsed according to a value of default_type parameter. The resulting structure of the output depends on the selected default_type value, the respective function for parsing (see default_type) and additional parameters that are passed to the function for parsing. If 'DraCor' API is not available, NULL is returned invisibly (see Details).

Time limits

Two time limits apply to every request to 'DraCor' API. Both can be changed with options():

rdracor.connect_timeout

Seconds to wait for the connection to the server, 30 by default. If the server does not accept the connection within this time, it is treated as unavailable.

rdracor.timeout

Seconds to wait for the whole response, 600 (10 minutes) by default. Some requests, e.g. metadata of a big corpus, can take several minutes on a slow connection.

For example, to wait up to 30 minutes for a response, run options(rdracor.timeout = 1800) before requesting data; to restore the default, run options(rdracor.timeout = NULL). To make the setting permanent, add the options() call to your .Rprofile.

See Also

dracor_sparql dracor_api_available

Examples


dracor_api("https://dracor.org/api/v1/info", expected_type = "application/json")


rdracor documentation built on Oct. 22, 2026, 1:07 a.m.