Learn R Programming

reqres (version 1.2.0)

mock_request: 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"
)

Value

A Request object

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

Examples

Run this code
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()

Run the code above in your browser using DataLab