Learn R Programming

webmockr (version 0.1.0)

StubbedRequest: StubbedRequest class

Description

StubbedRequest class

Arguments

method
the HTTP method (any, head, get, post, put, patch, or delete). "any" matches any HTTP method. required.
uri
(character) request URI. either this or uri_regex required
uri_regex
(character) request URI as regex. either this or uri required

Details

Methods
with(query, body, headers)
Set expectations for what's given in HTTP request
  • query (list) request query params, as a named list. optional
  • body (list) request body, as a named list. optional
  • headers (list) request headers as a named list. optional.

to_return(status, body, headers)
Set expectations for what's returned in HTTP resonse
  • status (numeric) an HTTP status code
  • body (list) response body, as a list. optional
  • headers (list) named list, response headers. optional.

to_s()
Response as a string

See Also

stub_request()

Examples

Run this code
## Not run: ------------------------------------
# x <- StubbedRequest$new(method = "get", uri = "api.crossref.org")
# x$method
# x$uri
# x$with(headers = list('User-Agent' = 'R'))
# x$to_return(status = 200, body = "foobar", headers = list(a = 5))
# x
# x$to_s()
# 
# # uri_regex
# (x <- StubbedRequest$new(method = "get", uri_regex = ".+ossref.org"))
# x$method
# x$uri
# x$to_s()
## ---------------------------------------------

Run the code above in your browser using DataLab