apifetch is a small, dependency-light toolkit for talking to
token-authenticated REST APIs from R. It handles three recurring chores:
It is the generic engine extracted from the
BigDataPE package;
BigDataPE is now just one use case (see vignette("bigdatape")). A
Python sibling lives at
apifetch-py.
Install the released version from CRAN:
install.packages("apifetch")
Or the development version from GitHub:
# install.packages("pak")
# pak::pak("StrategicProjects/apifetch")
install.packages("apifetch", repos = c('https://strategicprojects.r-universe.dev', 'https://cloud.r-project.org'))
library(apifetch)
# 1. Describe the API once: where, how to authenticate, how to paginate.
api <- af_api(
endpoint = "https://api.example.com/v1/search",
service = "Example",
auth = af_auth_bearer(), # "Authorization: Bearer <token>"
pagination = af_paginate_offset("query")
)
# 2. Store a token (kept only in this session's environment).
af_store_token("reports", "my-secret-token", service = "Example")
# 3. Fetch.
one_page <- af_fetch(api, "reports", limit = 50)
everything <- af_fetch_all(api, "reports", chunk_size = 1000)
Authentication: af_auth_bearer(), af_auth_raw(), af_auth_header(),
af_auth_query().
Pagination: af_paginate_offset(where = "header" | "query"),
af_paginate_none(). ```