Learn R Programming

httptest (version 3.0.0)

fake_response: Return something that looks like an httr 'response'

Description

These functions allow mocking of HTTP requests without requiring an internet connection or server to run against. Their return shape is a 'httr' "response" class object that should behave like a real response generated by a real request.

Usage

fake_response(request, verb = "GET", status_code = 200, headers = list(),
  content = NULL)

fakeResponse(request, verb = "GET", status_code = 200, headers = list(), content = NULL)

Arguments

request

An 'httr' request-class object. A character URL is also accepted, for which a fake request object will be created, using the verb argument as well.

verb

Character name for the HTTP verb, if request is a URL. Default is "GET".

status_code

Integer HTTP response status

headers

Optional list of additional response headers to return

content

If supplied, a JSON-serializable list that will be returned as response content with Content-Type: application/json. If no content is provided, and if the status_code is not 204 No Content, the url will be set as the response content with Content-Type: text/plain.

Value

An 'httr' response class object.