Requests are translated to mock file paths according to several rules that incorporate the request method, URL, query parameters, and body.




A httr2_request object


A file path and name, without an extension. The file, or a file with some extension appended, may or may not exist: existence is not a concern of this function.


First, the request protocol, such as "https://", is removed from the URL. Second, if the request URL contains a query string, it will be popped off, hashed by digest::digest(), and the first six characters appended to the file being read. Third, request bodies are similarly hashed and appended. Finally, if a request method other than GET is used it will be appended to the end of the end of the file name.

Mock file paths also have a file extension appended, based on the Content-Type of the response, though this function, which is only concerned with the request, does not add the extension. In an HTTP API, a "directory" itself is a resource, so the extension allows distinguishing directories and files in the file system. That is, a mocked GET may read a "" file, while GET reads "".

Other examples:

  • GET may read "".

  • POST may read "".

Note that if you are trying to guess the mock file paths corresponding to a test for which you intend to create a mock file manually, instead of trying to build the URL, you should run the test with with_mock_api() as the error message will contain the mock file path.