Skip to content

mikmart/httc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
#>    user  system elapsed 
#>    0.12    0.09    1.21
system.time(cached_request()) # Second uses cached result
#>    user  system elapsed 
#>    0.01    0.00    0.01
Sys.sleep(2)
system.time(cached_request()) # Re-requested from server
#>    user  system elapsed 
#>    0.02    0.00    0.13

About

HTTP Requests with Automatic Caching

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages