{"id":25298846,"url":"https://github.com/ishikawa/ex_fake_http","last_synced_at":"2025-07-22T11:38:30.421Z","repository":{"id":62429110,"uuid":"163478907","full_name":"ishikawa/ex_fake_http","owner":"ishikawa","description":"A scriptable HTTP server for testing your Elixir project.","archived":false,"fork":false,"pushed_at":"2020-02-11T02:52:12.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T11:11:20.845Z","etag":null,"topics":["elixir","http-server","mock-server","testing"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ishikawa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-29T05:27:42.000Z","updated_at":"2023-03-05T02:32:45.000Z","dependencies_parsed_at":"2022-11-01T20:04:33.294Z","dependency_job_id":null,"html_url":"https://github.com/ishikawa/ex_fake_http","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ishikawa/ex_fake_http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishikawa%2Fex_fake_http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishikawa%2Fex_fake_http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishikawa%2Fex_fake_http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishikawa%2Fex_fake_http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ishikawa","download_url":"https://codeload.github.com/ishikawa/ex_fake_http/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishikawa%2Fex_fake_http/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265507238,"owners_count":23778913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","http-server","mock-server","testing"],"created_at":"2025-02-13T04:52:15.820Z","updated_at":"2025-07-22T11:38:30.400Z","avatar_url":"https://github.com/ishikawa.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FakeHTTP\n\n[![CircleCI](https://circleci.com/gh/ishikawa/ex_fake_http.svg?style=shield)](https://circleci.com/gh/ishikawa/ex_fake_http)\n[![Hex pm](http://img.shields.io/hexpm/v/ex_fake_http.svg?style=flat)](https://hex.pm/packages/ex_fake_http)\n\nThis library provides a scriptable HTTP server for testing HTTP based service (e.g. REST API). It makes easy to set up the server's resposens and test your code sends expected HTTP requests.\n\n## Install\n\nTo use FakeHTTP in your Mix projects, first add FakeHTTP as a dependency.\n\n```elixir\ndef deps do\n  [\n    {:ex_fake_http, \"~\u003e 0.3.0\", only: :test}\n  ]\nend\n```\n\nAfter adding FakeHTTP as a dependency, run `mix deps.get` to install it.\n\n## Usage\n\nThe only public module in this library is `FakeHTTP.Server` module.\n\n`FakeHTTP.Server` implements full-fledged HTTP server. It establishes a real TCP\nconnection between it and a client. You can use it the same way that you use\nother mocking libraries:\n\n1. Start a process of server.\n2. Script the mock responses.\n3. Run your code.\n4. Verify that the expected requests were made.\n\n```elixir\ndefmodule YourApp.YourModuleTest do\n  # Each test has its `FakeHTTP.Server` instance.\n  # So it can be configured with `async` option enabled.\n  use ExUnit.Case, async: true\n\n  alias YourApp.ChatService\n\n  setup_all do\n    # Launch a HTTP server and internal Erlang process to\n    # manage HTTP server.\n    server = start_supervised!(FakeHTTP.Server)\n    base_url = FakeHTTP.Server.base_url(server)\n\n    {:ok, %{server: server, base_url: base_url}}\n  end\n\n  setup %{server: server} do\n    # Reset internal states before each test started.\n    FakeHTTP.Server.reset(server)\n    :ok\n  end\n\n  test \"GET from REST API\", %{server: server, base_url: base_url} do\n    path = \"/messages/1\"\n    auth_header = \"Basic dGVzdDp0ZXN0\"\n\n    # Register an expected response which the server should return for\n    # the next request from a client.\n    FakeHTTP.Server.enqueue(server, %{message: \"hello\"})\n\n    # The started server is a real HTTP server. You can use your favorite\n    # HTTP library to make a HTTP request without monkey-patched mocking.\n    assert {:ok, response} = HTTPoison.get(base_url \u003c\u003e path, %{\"Authorization\" =\u003e auth_header})\n\n    assert response.status_code == 200\n    assert :proplists.get_value(\"content-type\", response.headers) == \"application/json\"\n    assert Jason.decode!(response.body) == %{\"message\" =\u003e \"hello\"}\n\n    # Verify that the expected requests were made.\n    {:ok, req} = FakeHTTP.Server.take(server)\n\n    # Notice the `req` is an instance of `FakeHTTP.Request`.\n    assert req.method == :get\n    assert req.request_path == path\n    assert req.headers[\"authorization\"] == auth_header\n  end\nend\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fishikawa%2Fex_fake_http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fishikawa%2Fex_fake_http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fishikawa%2Fex_fake_http/lists"}