fake_server v2.1.0 FakeServer.Response
Response structure and helpers.
FakeServer makes use of the %FakeServer.Response{}
structure to define the responses that will be given by the server.
Structure Fields
:status
: The status code of the response. It must be an integer.:body
: Optional. The response body. Can be a string or a map. If the body is a map, it will be encoded so the map must be equivalent to a valid JSON.:headers
: Optional. The response headers. Must be a map with the string keys.
You can use the new/3
function to create a response. Since this function performs several validations, you should avoid to create the structure directly.
Link to this section Summary
Functions
Creates a new response with status 202
Creates a new response with status 202 and returns it
Returns a list with all 4xx HTTP methods available
Similar to all_4xx/0
, but excludes the status codes in parameter
Returns a list with all 5xx HTTP methods available
Similar to all_5xx/0
, but excludes the status codes in parameter
Creates a new response with status 502
Creates a new response with status 502 and returns it
Creates a new response with status 400
Creates a new response with status 400 and returns it
Creates a new response with status 409
Creates a new response with status 409 and returns it
Creates a new response with status 201
Creates a new response with status 201 and returns it
FakeServer default response. Used when there are no responses left to reply
Similar to default/0
Creates a new response with status 417
Creates a new response with status 417 and returns it
Creates a new response with status 424
Creates a new response with status 424 and returns it
Creates a new response with status 403
Creates a new response with status 403 and returns it
Creates a new response with status 504
Creates a new response with status 504 and returns it
Creates a new response with status 410
Creates a new response with status 410 and returns it
Creates a new response with status 505
Creates a new response with status 505 and returns it
Creates a new response with status 418
Creates a new response with status 418 and returns it
Creates a new response with status 507
Creates a new response with status 507 and returns it
Creates a new response with status 500
Creates a new response with status 500 and returns it
Creates a new response with status 411
Creates a new response with status 411 and returns it
Creates a new response with status 423
Creates a new response with status 423 and returns it
Creates a new response with status 405
Creates a new response with status 405 and returns it
Creates a new response with status 511
Creates a new response with status 511 and returns it
Creates a new Response structure. Returns {:ok, response}
on success or {:error, reason}
when validation fails
Similar to new/3
, but raises FakeServer.Error
when validation fails
Creates a new response with status 204
Creates a new response with status 204 and returns it
Creates a new response with status 203
Creates a new response with status 203 and returns it
Creates a new response with status 406
Creates a new response with status 406 and returns it
Creates a new response with status 510
Creates a new response with status 510 and returns it
Creates a new response with status 404
Creates a new response with status 404 and returns it
Creates a new response with status 501
Creates a new response with status 501 and returns it
Creates a new response with status 200
Creates a new response with status 200 and returns it
Creates a new response with status 206
Creates a new response with status 206 and returns it
Creates a new response with status 413
Creates a new response with status 413 and returns it
Creates a new response with status 412
Creates a new response with status 412 and returns it
Creates a new response with status 428
Creates a new response with status 428 and returns it
Creates a new response with status 407
Creates a new response with status 407 and returns it
Creates a new response with status 431
Creates a new response with status 431 and returns it
Creates a new response with status 408
Creates a new response with status 408 and returns it
Creates a new response with status 205
Creates a new response with status 205 and returns it
Creates a new response with status 503
Creates a new response with status 503 and returns it
Creates a new response with status 429
Creates a new response with status 429 and returns it
Creates a new response with status 401
Creates a new response with status 401 and returns it
Creates a new response with status 422
Creates a new response with status 422 and returns it
Creates a new response with status 415
Creates a new response with status 415 and returns it
Creates a new response with status 426
Creates a new response with status 426 and returns it
Creates a new response with status 414
Creates a new response with status 414 and returns it
Creates a new response with status 506
Creates a new response with status 506 and returns it
Link to this section Functions
accepted(body \\ "", headers \\ %{})
Creates a new response with status 202
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
accepted!(body \\ "", headers \\ %{})
Creates a new response with status 202 and returns it.
Raises FakeServer.Error
if the validation fails.
all_4xx()
Returns a list with all 4xx HTTP methods available
all_4xx(list)
Similar to all_4xx/0
, but excludes the status codes in parameter.
all_5xx()
Returns a list with all 5xx HTTP methods available.
all_5xx(list)
Similar to all_5xx/0
, but excludes the status codes in parameter.
bad_gateway(body \\ "", headers \\ %{})
Creates a new response with status 502
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
bad_gateway!(body \\ "", headers \\ %{})
Creates a new response with status 502 and returns it.
Raises FakeServer.Error
if the validation fails.
bad_request(body \\ "", headers \\ %{})
Creates a new response with status 400
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
bad_request!(body \\ "", headers \\ %{})
Creates a new response with status 400 and returns it.
Raises FakeServer.Error
if the validation fails.
conflict(body \\ "", headers \\ %{})
Creates a new response with status 409
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
conflict!(body \\ "", headers \\ %{})
Creates a new response with status 409 and returns it.
Raises FakeServer.Error
if the validation fails.
created(body \\ "", headers \\ %{})
Creates a new response with status 201
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
created!(body \\ "", headers \\ %{})
Creates a new response with status 201 and returns it.
Raises FakeServer.Error
if the validation fails.
default()
FakeServer default response. Used when there are no responses left to reply.
iex> FakeServer.Response.default()
{:ok,
%FakeServer.Response{
body: "{"message": "This is a default response from FakeServer"}",
headers: %{},
status: 200
}
}
default!()
Similar to default/0
.
expectation_failed(body \\ "", headers \\ %{})
Creates a new response with status 417
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
expectation_failed!(body \\ "", headers \\ %{})
Creates a new response with status 417 and returns it.
Raises FakeServer.Error
if the validation fails.
failed_dependency(body \\ "", headers \\ %{})
Creates a new response with status 424
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
failed_dependency!(body \\ "", headers \\ %{})
Creates a new response with status 424 and returns it.
Raises FakeServer.Error
if the validation fails.
forbidden(body \\ "", headers \\ %{})
Creates a new response with status 403
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
forbidden!(body \\ "", headers \\ %{})
Creates a new response with status 403 and returns it.
Raises FakeServer.Error
if the validation fails.
gateway_timeout(body \\ "", headers \\ %{})
Creates a new response with status 504
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
gateway_timeout!(body \\ "", headers \\ %{})
Creates a new response with status 504 and returns it.
Raises FakeServer.Error
if the validation fails.
gone(body \\ "", headers \\ %{})
Creates a new response with status 410
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
gone!(body \\ "", headers \\ %{})
Creates a new response with status 410 and returns it.
Raises FakeServer.Error
if the validation fails.
http_version_not_supported(body \\ "", headers \\ %{})
Creates a new response with status 505
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
http_version_not_supported!(body \\ "", headers \\ %{})
Creates a new response with status 505 and returns it.
Raises FakeServer.Error
if the validation fails.
im_a_teapot(body \\ "", headers \\ %{})
Creates a new response with status 418
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
im_a_teapot!(body \\ "", headers \\ %{})
Creates a new response with status 418 and returns it.
Raises FakeServer.Error
if the validation fails.
insufficient_storage(body \\ "", headers \\ %{})
Creates a new response with status 507
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
insufficient_storage!(body \\ "", headers \\ %{})
Creates a new response with status 507 and returns it.
Raises FakeServer.Error
if the validation fails.
internal_server_error(body \\ "", headers \\ %{})
Creates a new response with status 500
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
internal_server_error!(body \\ "", headers \\ %{})
Creates a new response with status 500 and returns it.
Raises FakeServer.Error
if the validation fails.
length_required(body \\ "", headers \\ %{})
Creates a new response with status 411
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
length_required!(body \\ "", headers \\ %{})
Creates a new response with status 411 and returns it.
Raises FakeServer.Error
if the validation fails.
locked(body \\ "", headers \\ %{})
Creates a new response with status 423
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
locked!(body \\ "", headers \\ %{})
Creates a new response with status 423 and returns it.
Raises FakeServer.Error
if the validation fails.
method_not_allowed(body \\ "", headers \\ %{})
Creates a new response with status 405
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
method_not_allowed!(body \\ "", headers \\ %{})
Creates a new response with status 405 and returns it.
Raises FakeServer.Error
if the validation fails.
network_authentication_required(body \\ "", headers \\ %{})
Creates a new response with status 511
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
network_authentication_required!(body \\ "", headers \\ %{})
Creates a new response with status 511 and returns it.
Raises FakeServer.Error
if the validation fails.
new(status_code, body \\ "", headers \\ %{})
Creates a new Response structure. Returns {:ok, response}
on success or {:error, reason}
when validation fails
Example
iex> FakeServer.Response.new(200, %{name: "Test User", email: "test_user@test.com"}, %{"Content-Type" => "application/json"})
iex> FakeServer.Response.new(200, ~s<{"name":"Test User","email":"test_user@test.com"}>, %{"Content-Type" => "application/json"})
iex> FakeServer.Response.new(201, ~s<{"name":"Test User","email":"test_user@test.com"}>)
iex> FakeServer.Response.new(404)
new!(status_code, body \\ "", headers \\ %{})
Similar to new/3
, but raises FakeServer.Error
when validation fails.
no_content(body \\ "", headers \\ %{})
Creates a new response with status 204
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
no_content!(body \\ "", headers \\ %{})
Creates a new response with status 204 and returns it.
Raises FakeServer.Error
if the validation fails.
non_authoritative_information(body \\ "", headers \\ %{})
Creates a new response with status 203.
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
non_authoritative_information!(body \\ "", headers \\ %{})
Creates a new response with status 203 and returns it.
Raises FakeServer.Error
if the validation fails.
not_acceptable(body \\ "", headers \\ %{})
Creates a new response with status 406
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
not_acceptable!(body \\ "", headers \\ %{})
Creates a new response with status 406 and returns it.
Raises FakeServer.Error
if the validation fails.
not_extended(body \\ "", headers \\ %{})
Creates a new response with status 510
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
not_extended!(body \\ "", headers \\ %{})
Creates a new response with status 510 and returns it.
Raises FakeServer.Error
if the validation fails.
not_found(body \\ "", headers \\ %{})
Creates a new response with status 404
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
not_found!(body \\ "", headers \\ %{})
Creates a new response with status 404 and returns it.
Raises FakeServer.Error
if the validation fails.
not_implemented(body \\ "", headers \\ %{})
Creates a new response with status 501
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
not_implemented!(body \\ "", headers \\ %{})
Creates a new response with status 501 and returns it.
Raises FakeServer.Error
if the validation fails.
ok(body \\ "", headers \\ %{})
Creates a new response with status 200
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
ok!(body \\ "", headers \\ %{})
Creates a new response with status 200 and returns it.
Raises FakeServer.Error
if the validation fails.
partial_content(body \\ "", headers \\ %{})
Creates a new response with status 206
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
partial_content!(body \\ "", headers \\ %{})
Creates a new response with status 206 and returns it.
Raises FakeServer.Error
if the validation fails.
payload_too_large(body \\ "", headers \\ %{})
Creates a new response with status 413
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
payload_too_large!(body \\ "", headers \\ %{})
Creates a new response with status 413 and returns it.
Raises FakeServer.Error
if the validation fails.
precondition_failed(body \\ "", headers \\ %{})
Creates a new response with status 412
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
precondition_failed!(body \\ "", headers \\ %{})
Creates a new response with status 412 and returns it.
Raises FakeServer.Error
if the validation fails.
precondition_required(body \\ "", headers \\ %{})
Creates a new response with status 428
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
precondition_required!(body \\ "", headers \\ %{})
Creates a new response with status 428 and returns it.
Raises FakeServer.Error
if the validation fails.
proxy_authentication_required(body \\ "", headers \\ %{})
Creates a new response with status 407
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
proxy_authentication_required!(body \\ "", headers \\ %{})
Creates a new response with status 407 and returns it.
Raises FakeServer.Error
if the validation fails.
request_header_fields_too_large(body \\ "", headers \\ %{})
Creates a new response with status 431
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
request_header_fields_too_large!(body \\ "", headers \\ %{})
Creates a new response with status 431 and returns it.
Raises FakeServer.Error
if the validation fails.
request_timeout(body \\ "", headers \\ %{})
Creates a new response with status 408
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
request_timeout!(body \\ "", headers \\ %{})
Creates a new response with status 408 and returns it.
Raises FakeServer.Error
if the validation fails.
reset_content(body \\ "", headers \\ %{})
Creates a new response with status 205
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
reset_content!(body \\ "", headers \\ %{})
Creates a new response with status 205 and returns it.
Raises FakeServer.Error
if the validation fails.
too_many_requests(body \\ "", headers \\ %{})
Creates a new response with status 429
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
too_many_requests!(body \\ "", headers \\ %{})
Creates a new response with status 429 and returns it.
Raises FakeServer.Error
if the validation fails.
unauthorized(body \\ "", headers \\ %{})
Creates a new response with status 401
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
unauthorized!(body \\ "", headers \\ %{})
Creates a new response with status 401 and returns it.
Raises FakeServer.Error
if the validation fails.
unprocessable_entity(body \\ "", headers \\ %{})
Creates a new response with status 422
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
unprocessable_entity!(body \\ "", headers \\ %{})
Creates a new response with status 422 and returns it.
Raises FakeServer.Error
if the validation fails.
unsupported_media_type(body \\ "", headers \\ %{})
Creates a new response with status 415
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
unsupported_media_type!(body \\ "", headers \\ %{})
Creates a new response with status 415 and returns it.
Raises FakeServer.Error
if the validation fails.
upgrade_required(body \\ "", headers \\ %{})
Creates a new response with status 426
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
upgrade_required!(body \\ "", headers \\ %{})
Creates a new response with status 426 and returns it.
Raises FakeServer.Error
if the validation fails.
uri_too_long(body \\ "", headers \\ %{})
Creates a new response with status 414
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
uri_too_long!(body \\ "", headers \\ %{})
Creates a new response with status 414 and returns it.
Raises FakeServer.Error
if the validation fails.
variant_also_negotiates(body \\ "", headers \\ %{})
Creates a new response with status 506
Returns {:ok, response}
tuple on succes and {:error, reason}
when validation fails.
variant_also_negotiates!(body \\ "", headers \\ %{})
Creates a new response with status 506 and returns it.
Raises FakeServer.Error
if the validation fails.