{"id":13836773,"url":"https://github.com/wooga/etest_http","last_synced_at":"2025-10-21T17:52:17.803Z","repository":{"id":3489031,"uuid":"4544986","full_name":"wooga/etest_http","owner":"wooga","description":"etest Assertions around HTTP (client-side)","archived":false,"fork":false,"pushed_at":"2019-03-02T14:11:11.000Z","size":64,"stargazers_count":52,"open_issues_count":1,"forks_count":20,"subscribers_count":74,"default_branch":"master","last_synced_at":"2024-11-29T10:07:46.470Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wooga.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2012-06-04T08:37:00.000Z","updated_at":"2023-06-26T22:14:10.000Z","dependencies_parsed_at":"2022-09-03T23:53:06.918Z","dependency_job_id":null,"html_url":"https://github.com/wooga/etest_http","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooga%2Fetest_http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooga%2Fetest_http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooga%2Fetest_http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooga%2Fetest_http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooga","download_url":"https://codeload.github.com/wooga/etest_http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228694079,"owners_count":17958191,"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":[],"created_at":"2024-08-04T15:00:54.228Z","updated_at":"2025-10-21T17:52:17.487Z","avatar_url":"https://github.com/wooga.png","language":"Erlang","funding_links":[],"categories":["Erlang","Other"],"sub_categories":["Scientific Computing"],"readme":"# etest_http\n\netest\\_http is a supplementary library for [etest](https://github.com/wooga/etest)\nthat makes it easy to test http APIs by providing useful assertions and helper\nmethods.\n\n## Example Test Case\n\n```erlang\n\n-module (my_api_test).\n-compile (export_all).\n\n% etest macros\n-include_lib (\"etest/include/etest.hrl\").\n% etest_http macros\n-include_lib (\"etest_http/include/etest_http.hrl\").\n\ntest_hello_world() -\u003e\n    Response = ?perform_get(\"http://localhost:3000/hello/world\"),\n    ?assert_status(200, Response),\n    ?assert_body_contains(\"Hello\", Response),\n    ?assert_body(\"Hello World\", Response).\n```\n\n## Installation\n\nInstall etest\\_http by adding it as a [rebar](https://github.com/basho/rebar)\ndependency:\n\n```erlang\n% rebar.config:\n{deps, [\n    {etest_http, \"\", {git, \"git://github.com/wooga/etest_http.git\"}},\n    % ...\n]}.\n```\n\nThen run `rebar get-deps` to synchronize your dependencies.\n\n## Usage\n\nThere are two kinds of macros which etest_http provides:\n\nThe [request macros](https://github.com/wooga/etest_http#request-macros) provide\na simple API to perform HTTP request. They return a response record on which\nsubsequent assertions are performed.\n\nThe [assertion macros](https://github.com/wooga/etest_http#assertion-macros)\nprovide useful http API related assertions.\n\n### Request Macros\n\n#### perform_get\n\nPerform a `GET` request, returns a response record.\n\n```erlang\nRes = ?perform_get(Url).\nRes = ?perform_get(Url, Headers).\nRes = ?perform_get(Url, Headers, Queries).\n\n% Url = string()\n% header() :: {string() | binary() | atom(), string() | binary()}\n% Headers = [header()]\n% query() :: [{string(), string()}]\n% Queries = [query()]\n```\n\n****\n\n#### perform_post\n\nPerform a `POST` request, returns a response record.\n\n```erlang\nRes = ?perform_post(Url).\nRes = ?perform_post(Url, Headers).\nRes = ?perform_post(Url, Headers, Body).\nRes = ?perform_post(Url, Headers, Body, Queries).\n\n% Url = string()\n% header() :: {string() | binary() | atom(), string() | binary()}\n% Headers = [header()]\n% query() :: [{string(), string()}]\n% Queries = [query()]\n% Body = binary()\n```\n\n\n### Assertion Macros\n\n#### assert_contains\n\nAssert that the `Haystack` contains the `Needle`, fail with `assert_contains`\notherwise.\n\n```erlang\n% Test Macro.\n?assert_contains(Needle, Haystack).\n\n% Test Generator Macro.\n?assert_contains(Needle, Haystack).\n\n% Needle = string()\n% Haystack = string()\n```\n\n****\n\n#### assert_body_contains\n\nAssert that the body received with the response `Res` contains the string\n`Needle`, fail with `assert_contains` otherwise too.\n\n```erlang\n% Test Macro.\n?assert_body_contains(Needle, Res).\n\n% Test Generator Macro.\n?assert_body_contains(Needle, Res).\n\n% Needle = string()\n```\n\n****\n\n#### assert_body\n\nAssert that the body received with the response `Res` is exactly `Body`, fail\nwith `assert_equal` otherwise.\n\n```erlang\n?assert_body(Body, Res).\n\n% Test Generator Macro.\n?assert_body(Body, Res).\n\n% Body = binary()\n```\n\n**Planned for future versions:**\n* Support for regular expressions\n\n****\n\n#### assert_header\n\nAssert that the presence of a header `HeaderName` in the headers received with\nthe response `Res`, fail with `assert_header` otherwise.\n\n```erlang\n% Test Macro.\n?assert_header(HeaderName, Res).\n\n% Test Generator Macro.\n?assert_header(HeaderName, Res).\n\n% HeaderName = string()\n\n% Examples:\n?assert_header_val(\"X-Signature\", Res).\n```\n\n****\n\n#### assert_header_value\n\nAssert that the headers received with the response `Res` has a header\n`HeaderName` with value `HeaderValue`, fail with `assert_header_value` otherwise.\n\n```erlang\n% Test Macro.\n?assert_header_val(HeaderName, HeaderValue, Res).\n\n% Test Generator Macro.\n?assert_header_val(HeaderName, HeaderValue, Res).\n\n% HeaderName = string()\n% HeaderVal = string()\n\n% Examples:\n?assert_header_val(\n    \"X-Signature\", \"42UVoTWYp9I-wdWJsQYUyEXRoCI1wCXmOVPqwdV8LU0=\", Res).\n```\n\n****\n\n#### assert_status\n\nAssert that the response's HTTP status code is `StatusCode`, fail with\n`assert_status` otherwise.\n\n```erlang\n% Test Macro.\n?assert_status(StatusCode, Res).\n\n% Test Generator Macro.\n?assert_status(StatusCode, Res).\n\n% StatusCode = integer()\n\n% Example:\n?assert_status(200, Res).\n```\n\n****\n\n#### assert_json\n\nAssert that the body received with the response `Res` contains a JSON structure\nequal to `JsonStruct`, fail with `assert_equal` otherwise.\n\n```erlang\n% Test Macro.\n?assert_json(JsonStruct, Res).\n\n% Test Generator Macro.\n?assert_json(JsonStruct, Res).\n\n% JsonStruct = orddict()\n\n% Example:\n?assert_json([{message, \"Hello World\"}], Res).\n```\n\n****\n\n#### assert_json_key\n\nAssert that the body received with the response `Res` contains a JSON object,\nwhich has a key `Key` with arbitrary contents, fail with `assert_json_key`\notherwise.\n\n```erlang\n% Test Macro.\n?assert_json_key(Key, Res).\n\n% Test Generator Macro.\n?assert_json_key(Key, Res).\n\n% Key = binary() | [binary()]\n\n% Examples:\n?assert_json_key(\u003c\u003c\"message\"\u003e\u003e, Res).\n?assert_json_key([\u003c\u003c\"messages\"\u003e\u003e, \u003c\u003c\"en\"\u003e\u003e], Res).\n```\n\n****\n\n#### assert_json_value\n\nAssert that the body received with the response `Res` contains a JSON object, which under the key `Key` contains exactly `Val`, fail with `assert_json_value` otherwise.\n\n```erlang\n% Test Macro.\n?assert_json_value(Key, Val, Res).\n\n% Test Generator Macro.\n?assert_json_value(Key, Val, Res).\n\n% Key = binary() | [binary()]\n% Val = atom() | binary() | list() | integer() | float() | {list()}\n\n% Examples:\n?assert_json_value(\u003c\u003c\"message\"\u003e\u003e, \u003c\u003c\"Hello World\"\u003e\u003e, Res).\n?assert_json_value(\u003c\u003c\"should_reload\"\u003e\u003e, true, Res).\n?assert_json_value([\u003c\u003c\"messages\"\u003e\u003e, \u003c\u003c\"de\"\u003e\u003e], \u003c\u003c\"Hallo Welt\"\u003e\u003e, Res).\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooga%2Fetest_http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooga%2Fetest_http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooga%2Fetest_http/lists"}