knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

httc

Lifecycle: experimental

httc makes it easy to quickly cache HTTP responses according to cache control headers with drop in wrappers for httr verbs. For more control over caching behaviour, caching() lets you customize your own cached function.

Installation

httc is not on CRAN. You can install the development version on GitHub with:

remotes::install_github("mikmart/httc")

Example

Drop in a httc::GET instead of httr::GET to honour cache control headers:

# Response header specifies two seconds of caching
cached_request <- function() {
  try(httc::GET("https://httpbin.org/cache/2"))
}

system.time(cached_request()) # First response from server
system.time(cached_request()) # Second uses cached result
Sys.sleep(2)
system.time(cached_request()) # Re-requested from server


mikmart/httc documentation built on Dec. 21, 2021, 6:57 p.m.