socialmixr icon indicating copy to clipboard operation
socialmixr copied to clipboard

Add custom user agent for socialmixr

Open Bisaloo opened this issue 3 years ago • 2 comments

It is generally considered good practice for package that interact with API or do webscraping to have a custom user agent.

This would allow zenodo maintainer to know which requests come from the package, and possibly reach out to us if it's not behaving correctly, or even let us know in advance if they plan breaking changes that would impact us.

Bisaloo avatar Nov 07 '22 09:11 Bisaloo

This sounds like a good idea. It seems this can be achieved using the httr::add_headers function passed as an argument to our httr::GET calls. It seems this can be set to anything. Do you have any examples/suggestions for what we should put?

sbfnk avatar Nov 10 '22 08:11 sbfnk

Guidelines from the relevant htt2 vignette:

If you’re wrapping this code into a package, it’s considered polite to set a user agent, so that, if your package accidentally does something horribly wrong, the developers of the website can figure out who to reach out to. You can do this with the req_user_agent() function:

req %>%
  req_user_agent("my_package_name (http://my.package.web.site)") %>%
  req_dry_run()
#> GET /api/v1 HTTP/1.1
#> Host: fakerapi.it
#> User-Agent: my_package_name (http://my.package.web.site)
#> Accept: */*
#> Accept-Encoding: deflate, gzip, br

This is an example of what we used in the now defunct rromeo package. I like the idea of putting the package version.

https://github.com/ropensci-archive/rromeo/blob/66a4914f15e473ec4e4d1248581510221b6969b2/R/rr_base_functions.R#L10-L14

Bisaloo avatar Nov 10 '22 09:11 Bisaloo