← Back to all sparks
W

webmockr

ANALYTICS
Velocity0.0

Stub and set expectations on HTTP requests. Contribute to ropensci/webmockr development by creating an account on GitHub.

The stubbing library added httr2 support, then spent a year cutting itself free of everything else

http-mockingtestinghttr2ropenscidependency-pruning
Current state
webmockr intercepts HTTP requests in R tests and returns stubbed responses, and since 1.0.0 it covers all three clients that matter — httr, httr2 and crul. The releases through 2025 have been about shedding dependencies: internal R6 classes unexported in 2.1.0, crul demoted from Imports to Suggests in the same release, and the mutual dependency with vcr severed in 2.2.0. The package now installs and runs without pulling in the rest of the rOpenSci HTTP stack.
Where it's heading
Two arcs run in sequence. The first is coverage — multiple queued responses in 0.7.0, basic auth mocking, async through crul, then httr2 — building out what can be stubbed. The second, starting with 2.0.0, is correctness and independence: stubs are now deleted if an error occurs mid-construction rather than lingering half-built, partial matching arrives for bodies and queries, and the dependency graph is pruned release by release. The 2.2.0 split from vcr landed within a minute of crul's release taking mocking control into its own clients.
Prediction
RequestPattern is documented as still exported in 2.1.0 but slated for removal, so the next major release is where that lands. Expect continued dependency pruning rather than new client support — the three clients that exist are already covered.

Recent moves

  1. 1y ago

    vcr dependency severed

    Severs the mutual dependency between webmockr and vcr — two packages that previously each required the other now stand alone, with no change to how either is used. Also fixes the quiet handling in enable()/disable() and eliminates partial match warnings.

    View source ↗
  2. 1y ago

    Internal classes unexported; crul becomes an optional dependency

    Unexports the internal-only R6 classes, with RequestPattern flagged as the last one still exported and due for removal next. crul moves from Imports to Suggests, with one crul call replaced by a curl equivalent so the dependency is genuinely optional unless you are mocking crul. httr2 mocking setup is also improved.

    View source ↗
  3. 1y ago

    Failed stub construction cleans up; partial matching extends to bodies and queries

    Changes stub construction semantics: an error partway through building a stub now removes it rather than leaving a partial stub registered, implemented via withCallingHandlers. It also extends partial matching from headers, where it already worked, to bodies and queries through the new including() and excluding() helpers — useful when a request carries twenty query parameters and only two identify it.

    View source ↗
  4. 2y ago

    httr2 joins httr and crul as a supported client

    ⚡ SPARK

    Adds httr2 support alongside httr and crul, and picks up async mocking with crul 1.5 or later without any change on webmockr's side. The entry is candid that httr2 behaves differently because it converts HTTP statuses of 400 and above into R errors, and that parallel httr2 requests remain unmockable because req_perform_parallel offers no hook.

    View source ↗
  5. 3y ago

    Queued responses, body matching and integer status codes fixed

    Repairs three matching defects at once: multiple queued responses from to_return() were broken internally, body-based stub matching failed in some cases, and to_return(status = 200L) errored despite integers being documented as acceptable. Config options that were advertised but never implemented are removed rather than left as dead surface.

    View source ↗
  6. 3y ago

    Regex URI matching fixed

    A single fix to UriPattern so regex matching behaves as intended. Narrow, though URI matching is the first thing every stub relies on.

    View source ↗