mock_request: Create a mock request to use in testing

View source: R/mock_request.R

mock_requestR Documentation

Create a mock request to use in testing

Description

This function creates a new Request for a specific resource defined by a URL.

Usage

mock_request(
  url,
  method = "get",
  content = "",
  headers = list(),
  app_location = "",
  remote_address = "123.123.123.123"
)

Arguments

url

A complete url for the resource the request should ask for, including querystring if needed

method

The request type (get, post, put, etc). Defaults to "get"

content

The content of the request, either a raw vector or a string

headers

A list of name-value pairs that defines the request headers

app_location

A string giving the first part of the url path that should be stripped from the path

remote_address

The IP address of the presumed sender

Value

A Request object

Examples

req <- mock_request(
    'http://www.my-fake-website.com/path/to/a/query/?key=value&key2=value2',
    content = 'Some important content'
)

# Get the main address of the URL
req$host

# Get the query string
req$query

# ... etc.

# Cleaning up connections
rm(req)
gc()


reqres documentation built on Dec. 11, 2025, 9:06 a.m.