Using test that with web APIs

apis

#1

I’ve started to develop a wrapper package for an API that I don’t believe has an R wrapper yet. I’ve got the Auth working and can retrieve data using the wonderful httr package. Where I am coming unstuck is how to approach the testing. I’ve seen the vignette for managing secrets however I can’t get my head around how to apply this in my particular case.

The API only authorises tokens for 30 mins at which point you need to re-authenticate which requires an interactive approval of the login. At this point I can’t create a token that can be refreshed without clicking to approve access.

Any thoughts on how to get around this would be super helpful.

For those interested to understand the API documentation it can be found here


#2

The httptest package may help in this case. Have a look at:

HTH


#3

I’ve been looking into similar topics lately. Here are some resources i found helpful.

rOpenSci best practices

testing without internet

vcr pkg

hth.


#4

httptest and vcr both look like great comprehensive options. A more lightweight option I used is Kirill Müller’s mockr::with_mock, which is a replacement for the sort-of deprecated (missing from the index, at least) testthat::with_mock.


#5

Thanks for the responses. I’ll have a look at those packages and see how things go. The httptest Package looks like it might be promising.