fake_server v1.4.0 FakeServer.HTTP.Response

Response structure

FakeServer makes use of the FakeServer.HTTP.Response structure to define the responses that will be given by the server.

The structure has the following fields:

  • :code: The status code of the response. It must be an integer.
  • :body: Optional. The response body. Can be a string or a map.
  • :headers: Optional. The response headers. Must be a map with the string keys.

You can use the new/3 function to create a new struct.

Link to this section Summary

Functions

Creates a new response with status code 202

Returns a list with all 4xx HTTP methods available

Returns a list with all 5xx HTTP methods available

Creates a new response with status code 502

Creates a new response with status code 400

Creates a new response with status code 409

Creates a new response with status code 201

FakeServer default response. Used when there are no responses left to reply

Creates a new response with status code 417

Creates a new response with status code 424

Creates a new response with status code 403

Creates a new response with status code 504

Creates a new response with status code 410

Creates a new response with status code 505

Creates a new response with status code 418

Creates a new response with status code 507

Creates a new response with status code 500

Creates a new response with status code 411

Creates a new response with status code 423

Creates a new response with status code 405

Creates a new response with status code 511

Creates a new Response structure

Creates a new response with status code 204

Creates a new response with status code 203

Creates a new response with status code 406

Creates a new response with status code 510

Creates a new response with status code 404

Creates a new response with status code 501

Creates a new response with status code 200

Creates a new response with status code 206

Creates a new response with status code 413

Creates a new response with status code 412

Creates a new response with status code 428

Creates a new response with status code 407

Creates a new response with status code 431

Creates a new response with status code 408

Creates a new response with status code 205

Creates a new response with status code 503

Creates a new response with status code 429

Creates a new response with status code 401

Creates a new response with status code 422

Creates a new response with status code 415

Creates a new response with status code 426

Creates a new response with status code 414

Creates a new response with status code 506

Link to this section Functions

Link to this function accepted(body \\ "", headers \\ %{})

Creates a new response with status code 202

Returns a list with all 4xx HTTP methods available

Returns a list with all 5xx HTTP methods available

Link to this function bad_gateway(body \\ "", headers \\ %{})

Creates a new response with status code 502

Link to this function bad_request(body \\ "", headers \\ %{})

Creates a new response with status code 400

Link to this function conflict(body \\ "", headers \\ %{})

Creates a new response with status code 409

Link to this function created(body \\ "", headers \\ %{})

Creates a new response with status code 201

FakeServer default response. Used when there are no responses left to reply.

Link to this function expectation_failed(body \\ "", headers \\ %{})

Creates a new response with status code 417

Link to this function failed_dependency(body \\ "", headers \\ %{})

Creates a new response with status code 424

Link to this function forbidden(body \\ "", headers \\ %{})

Creates a new response with status code 403

Link to this function gateway_timeout(body \\ "", headers \\ %{})

Creates a new response with status code 504

Link to this function gone(body \\ "", headers \\ %{})

Creates a new response with status code 410

Link to this function http_version_not_supported(body \\ "", headers \\ %{})

Creates a new response with status code 505

Link to this function im_a_teapot(body \\ "", headers \\ %{})

Creates a new response with status code 418

Link to this function insufficient_storage(body \\ "", headers \\ %{})

Creates a new response with status code 507

Link to this function internal_server_error(body \\ "", headers \\ %{})

Creates a new response with status code 500

Link to this function length_required(body \\ "", headers \\ %{})

Creates a new response with status code 411

Link to this function locked(body \\ "", headers \\ %{})

Creates a new response with status code 423

Link to this function method_not_allowed(body \\ "", headers \\ %{})

Creates a new response with status code 405

Link to this function network_authentication_required(body \\ "", headers \\ %{})

Creates a new response with status code 511

Link to this function new(status_code, body \\ "", headers \\ %{})

Creates a new Response structure.

Example

FakeServer.HTTP.Response.new(200, %{name: "Test User", email: "test_user@test.com"}, %{"Content-Type" => "application/json"})
FakeServer.HTTP.Response.new(200, ~s<{"name":"Test User","email":"test_user@test.com"}>, %{"Content-Type" => "application/json"})
FakeServer.HTTP.Response.new(201, ~s<{"name":"Test User","email":"test_user@test.com"}>)
FakeServer.HTTP.Response.new(404)
Link to this function no_content(body \\ "", headers \\ %{})

Creates a new response with status code 204

Link to this function non_authoritative_information(body \\ "", headers \\ %{})

Creates a new response with status code 203

Link to this function not_acceptable(body \\ "", headers \\ %{})

Creates a new response with status code 406

Link to this function not_extended(body \\ "", headers \\ %{})

Creates a new response with status code 510

Link to this function not_found(body \\ "", headers \\ %{})

Creates a new response with status code 404

Link to this function not_implemented(body \\ "", headers \\ %{})

Creates a new response with status code 501

Link to this function ok(body \\ "", headers \\ %{})

Creates a new response with status code 200

Link to this function partial_content(body \\ "", headers \\ %{})

Creates a new response with status code 206

Link to this function payload_too_large(body \\ "", headers \\ %{})

Creates a new response with status code 413

Link to this function precondition_failed(body \\ "", headers \\ %{})

Creates a new response with status code 412

Link to this function precondition_required(body \\ "", headers \\ %{})

Creates a new response with status code 428

Link to this function proxy_authentication_required(body \\ "", headers \\ %{})

Creates a new response with status code 407

Link to this function request_header_fields_too_large(body \\ "", headers \\ %{})

Creates a new response with status code 431

Link to this function request_timeout(body \\ "", headers \\ %{})

Creates a new response with status code 408

Link to this function reset_content(body \\ "", headers \\ %{})

Creates a new response with status code 205

Link to this function service_unavailable(body \\ "", headers \\ %{})

Creates a new response with status code 503

Link to this function too_many_requests(body \\ "", headers \\ %{})

Creates a new response with status code 429

Link to this function unauthorized(body \\ "", headers \\ %{})

Creates a new response with status code 401

Link to this function unprocessable_entity(body \\ "", headers \\ %{})

Creates a new response with status code 422

Link to this function unsupported_media_type(body \\ "", headers \\ %{})

Creates a new response with status code 415

Link to this function upgrade_required(body \\ "", headers \\ %{})

Creates a new response with status code 426

Link to this function uri_too_long(body \\ "", headers \\ %{})

Creates a new response with status code 414

Link to this function variant_also_negotiates(body \\ "", headers \\ %{})

Creates a new response with status code 506