DRDataRaft/ docs
GitHub ↗

dr_source_api()

Supply a prepared httr2 request, including authentication, retry and throttle policies, or a zero-argument factory that builds one at execution time. When no retry limit was configured, requests retry up to three attempts using httr2's transient-status rules. Request details, headers, URLs and response bodies are excluded from inspection and adapter error messages.

Usage

dr_source_api(
  request,
  parse = api_parse_json,
  next_request = NULL,
  max_pages = 1000L
)

Arguments

request
An httr2 request or zero-argument request factory.


parse
Function converting one response into a data frame.


next_request
Optional function returning the next request or NULL.


max_pages
Maximum number of pages, default 1000.

Value

A source specification for dataraft.core::dr_add_source().

Details

parse receives each response and must return a data frame. The default reads a JSON array of records, or a JSON object with a data array. next_request receives each response and returns another prepared request or NULL. Pagination must terminate before max_pages is exceeded; truncation fails rather than silently dropping rows. Repeated identical requests are rejected. Each page must have the same column names; incompatible types fail binding. Authentication and rate limiting remain httr2's responsibility.

Examples

\dontshow{if (requireNamespace("httr2", quietly = TRUE)) withAutoprint(\{ # examplesIf}
# Construction does not send a request.
api <- dr_source_api(httr2::request("https://example.org/orders"))
dataraft.core::dr_inspect(api)
\dontshow{\}) # examplesIf}
Documentation source snapshot · View source at 2f9432d ↗
Code examples are documented source examples; they are not executed in this website build.

Search documentation

Search functions, packages and guides.