BodyPattern | R Documentation |
body matcher
pattern
a list
partial
bool, default: FALSE
partial_type
a string, default: NULL
new()
Create a new BodyPattern
object
BodyPattern$new(pattern)
pattern
(list) a body object - from a request stub (i.e., the mock)
A new BodyPattern
object
matches()
Match a request body pattern against a pattern
BodyPattern$matches(body, content_type = "")
body
(list) the body, i.e., from the HTTP request
content_type
(character) content type
a boolean
to_s()
Print pattern for easy human consumption
BodyPattern$to_s()
a string
clone()
The objects of this class are cloneable with this method.
BodyPattern$clone(deep = FALSE)
deep
Whether to make a deep clone.
# make a request signature
bb <- RequestSignature$new(
method = "get",
uri = "https:/httpbin.org/get",
options = list(
body = list(foo = "bar", a = 5)
)
)
# make body pattern object
## FALSE
z <- BodyPattern$new(pattern = list(foo = "bar"))
z$pattern
z$matches(bb$body)
## TRUE
z <- BodyPattern$new(pattern = list(foo = "bar", a = 5))
z$pattern
z$matches(bb$body)
# uploads in bodies
## upload NOT in a list
bb <- RequestSignature$new(
method = "post", uri = "https:/httpbin.org/post",
options = list(body = crul::upload(system.file("CITATION")))
)
bb$body
z <- BodyPattern$new(
pattern =
crul::upload(system.file("CITATION"))
)
z$pattern
z$matches(bb$body)
## upload in a list
bb <- RequestSignature$new(
method = "post", uri = "https:/httpbin.org/post",
options = list(body = list(y = crul::upload(system.file("CITATION"))))
)
bb$body
z <- BodyPattern$new(
pattern =
list(y = crul::upload(system.file("CITATION")))
)
z$pattern
z$matches(bb$body)
# partial matching
## including
partial_incl <- including(list(foo = "bar"))
z <- BodyPattern$new(pattern = partial_incl)
z$pattern
z$matches(list(foo = "bar", a = 5)) # TRUE
## excluding
partial_excl <- excluding(list(hello = "world"))
z <- BodyPattern$new(pattern = partial_excl)
z$pattern
z$matches(list(a = 5)) # TRUE
z$matches(list(hello = "mars", a = 5)) # TRUE
z$matches(list(hello = "world")) # FALSE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.