fiery (version 0.2.1)

fake_request: Create a fake request to use in testing

Description

This function creates a new request for a specific ressource defined by a URL. It mimicks the format of the requests provided through httpuv, meaning that it can be used in place for the requests send to the 'before-request', 'request', and 'after-request' handlers. This is only provided so that handlers can be tested without having to start up a server.

Usage

fake_request(url, method = "get", appLocation = "", content = "", headers = list(), ...)

Arguments

url
A complete url for the ressource the request should ask for
method
The request type (get, post, put, etc). Defaults to "get"
appLocation
A string giving the first part of the url path that should be stripped from the path
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
...
Additional name-value pairs that should be added to the request

Value

A ROOK-compliant environment

Examples

Run this code
req <- fake_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[['SERVER_NAME']]

# Get the query string
req[['QUERY_STRING']]

# ... etc.

Run the code above in your browser using DataLab