{"id":13509171,"url":"https://github.com/FabioBatSilva/efrisby","last_synced_at":"2025-03-30T13:31:40.891Z","repository":{"id":57493714,"uuid":"51707591","full_name":"FabioBatSilva/efrisby","owner":"FabioBatSilva","description":"A REST API testing framework for erlang","archived":false,"fork":false,"pushed_at":"2017-02-05T00:24:58.000Z","size":50,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-12T03:46:04.695Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/efrisby","language":"Erlang","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/FabioBatSilva.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":"2016-02-14T18:36:15.000Z","updated_at":"2023-08-31T09:38:44.000Z","dependencies_parsed_at":"2022-08-30T04:01:51.236Z","dependency_job_id":null,"html_url":"https://github.com/FabioBatSilva/efrisby","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioBatSilva%2Fefrisby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioBatSilva%2Fefrisby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioBatSilva%2Fefrisby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioBatSilva%2Fefrisby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FabioBatSilva","download_url":"https://codeload.github.com/FabioBatSilva/efrisby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246323927,"owners_count":20759051,"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-01T02:01:03.976Z","updated_at":"2025-03-30T13:31:40.531Z","avatar_url":"https://github.com/FabioBatSilva.png","language":"Erlang","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"# efrisby\n\n[![Build Status](https://travis-ci.org/FabioBatSilva/efrisby.svg)](https://travis-ci.org/FabioBatSilva/efrisby)\n\nA REST API testing framework for erlang inspired by frisby-js\n\n## Installation\n\nBy adding the following dependency to your ```rebar.config``` file :\n\n```erlang\n\n%% Rebar3 test profiles\n{profiles, [\n    {test, [\n        {deps, [\n            {efrisby, \"0.2.0\"}\n        ]}\n    ]}\n]}.\n\n```\n\n## Basic Usage.\n\nYou have to start all ``efrisby`` dependencies before using any of the functions\n\n\nTo start in the console run:\n\n```erlang-repl\n$ rebar3 shell\n```\n\nAnd run the following command to start all of the application it depends on:\n\n```erlang\n   \u003e application:ensure_all_started(efrisby).\n%% \u003e ok,[idna,mimerl,certifi,hackney,efrisby]}\n```\n\n\n```erlang\n   \u003e efrisby:get(\"http://localhost/api/1.0/users/3.json\", [\n        {status, 200},\n        {content_type, \"application/json\"},\n        {json_types, [\n            {\u003c\u003c\"id\"\u003e\u003e, integer},\n            {\u003c\u003c\"is_admin\"\u003e\u003e, boolean},\n            {\u003c\u003c\"username\"\u003e\u003e, bitstring}\n        ]},\n        {json, [\n            {\u003c\u003c\"id\"\u003e\u003e, 3},\n            {\u003c\u003c\"is_admin\"\u003e\u003e, false},\n            {\u003c\u003c\"username\"\u003e\u003e, \u003c\u003c\"johndoe\"\u003e\u003e}\n        ]}\n    ]).\n%% \u003e {ok, Response}\n\n```\n\n\n## Write Tests\n\nefrisby tests start with one by calling one of ``get``, ``post``, ``put``, ``options``, ``delete``, or ``head`` to generate an HTTP request and assert the response.\n\nefrisby has many built-in test assertions like :\n\n* ``status`` to easily test HTTP status codes\n* ``content_type`` to test content type header\n* ``headers`` to test expected HTTP headers\n* ``json`` to test expected JSON keys/values\n* ``json_types`` to test JSON value types\n\neq :\n\n```erlang\n\n{ok, Response} = efrisby:get(\"https://api.github.com/users/FabioBatSilva\", [\n    {status, 200},\n    {content_type, \"application/json; charset=utf-8\"},\n    {json_types, [\n        {\u003c\u003c\"id\"\u003e\u003e, integer},\n        {\u003c\u003c\"url\"\u003e\u003e, bitstring},\n        {\u003c\u003c\"login\"\u003e\u003e, bitstring}\n    ]},\n    {json, [\n        {\u003c\u003c\"id\"\u003e\u003e, 588172},\n        {\u003c\u003c\"login\"\u003e\u003e, \u003c\u003c\"FabioBatSilva\"\u003e\u003e},\n        {\u003c\u003c\"url\"\u003e\u003e, \u003c\u003c\"https://api.github.com/users/FabioBatSilva\"\u003e\u003e}\n    ]}\n]).\n\n\u003e efrisby_resp:json(Response).\n[\n    {\u003c\u003c\"id\"\u003e\u003e, 588172},\n    {\u003c\u003c\"login\"\u003e\u003e, \u003c\u003c\"FabioBatSilva\"\u003e\u003e},\n    {\u003c\u003c\"url\"\u003e\u003e, \u003c\u003c\"https://api.github.com/users/FabioBatSilva\"\u003e\u003e}\n]\n```\n\n## Expectations\n\nExpectation are used to generate assertions on the response.\nThese helpers make testing API response bodies and headers easy with minimal time and effort.\n\n\n#### ``{status, integer()}``\n\nAssert that HTTP Status code equals expectation.\n\n```erlang\nefrisby:get(\"https://api.github.com/users/FabioBatSilva\", [\n    {status, 200}\n]).\n%% \u003e {ok, Response}\n```\n\n\n#### ``{headers, list()}``\n\nAssert the HTTP response headers.\n\n```erlang\nefrisby:get(\"https://api.github.com/users/FabioBatSilva\", [\n    {headers, [\n        {\u003c\u003c\"content-type\"\u003e\u003e, \u003c\u003c\"application/json; charset=utf-8\"\u003e\u003e}\n    ]}\n]).\n%% \u003e {ok, Response}\n```\n\n\n#### ``{json, bitstring() | none(), list() | integer() | atom() | bitstring()}``\n\nTests that response JSON body contains the provided keys/values in the response.\n\n```erlang\nefrisby:get(\"https://api.github.com/users/FabioBatSilva\", [\n    {json, [\n        {\u003c\u003c\"id\"\u003e\u003e, 588172},\n        {\u003c\u003c\"login\"\u003e\u003e, \u003c\u003c\"FabioBatSilva\"\u003e\u003e}\n    ]}\n]).\n%% \u003e {ok, Response}\n\nefrisby:get(\"https://api.github.com/users/FabioBatSilva\", [\n    {json, \".id\", 588172},\n    {json, \".login\", \u003c\u003c\"FabioBatSilva\"\u003e\u003e}\n]).\n%% \u003e {ok, Response}\n```\n\n\n#### ``{json_types, bitstring() | none(), list()}``\n\nTests that response JSON body contains the provided keys/values types.\n\n```erlang\nefrisby:get(\"https://api.github.com/users/FabioBatSilva\", [\n    {json_types, [\n        {\u003c\u003c\"id\"\u003e\u003e, integer},\n        {\u003c\u003c\"login\"\u003e\u003e, bitstring}\n    ]}\n]).\n%% \u003e {ok, Response}\n```\n\n#### Using Paths with ``json`` and ``json_types``\n\nBoth ``json`` and ``json_types`` accept a tuple containing a path.\nThe path value can be a nested path separated by periods, like ``args.foo.mypath``, a simple path like ``.results`` or ``.`` to test the whole JSON value.\n\n```erlang\nefrisby:get(\"http://httpbin.org/get?foo=bar\u0026bar=baz\", [\n    {json_types, \".args\", [\n        {\u003c\u003c\"bar\"\u003e\u003e, bitstring},\n        {\u003c\u003c\"foo\"\u003e\u003e, bitstring}\n    ]},\n    {json, \".args\", [\n        {\u003c\u003c\"foo\"\u003e\u003e, \u003c\u003c\"bar\"\u003e\u003e},\n        {\u003c\u003c\"bar\"\u003e\u003e, \u003c\u003c\"baz\"\u003e\u003e}\n    ]}\n]).\n%% \u003e {ok, Response}\n```\n\n## Request Methods\n\nefrisby support your basic HTTP verbs..\n\n* ``efrisby:get(url(), expectations(), options())``\n* ``efrisby:head(url(), expectations(), options())``\n* ``efrisby:options(url(), expectations(), options())``\n* ``efrisby:put(url(), body(), expectations(), options())``\n* ``efrisby:post(url(), body(), expectations(), options())``\n* ``efrisby:patch(url(), body(), expectations(), options())``\n* ``efrisby:delete(url(), body(), expectations(), options())``\n\n\nEvery request method accepts an optional list of parameters as its last argument,\nRequest options control various aspects of a request including, headers, timeout settings and more.\n\neq :\n\n```erlang\n-define(OPTIONS, [\n    {failure_callback, fun erlang:display/1},\n    {http_options, [{timeout, 150000}]},\n    {base_url, \"https://myapi.local\"},\n    {headers, [\n        {\"Accept\", \"application/json\"}\n    ]}\n]).\n```\n\n* ``http_options`` Options for hackney http client (see https://github.com/benoitc/hackney)\n* ``failure_callback`` Assertion failure callback function\n* ``base_url`` Base request url\n* ``headers`` Http headers\n\n#### ``efrisby:get(url(), expectations(), options())``\n\nGET request.\n\n```erlang\nefrisby:get(\"/users/FabioBatSilva\", [\n    {status, 200}\n], ?OPTIONS).\n%% \u003e {ok, Response}\n```\n\n#### ``efrisby:post(url(), body(), expectations(), options())``\n\nPOST request.\n\n```erlang\n\nBody = [\n    {\u003c\u003c\"login\"\u003e\u003e, \u003c\u003c\"FabioBatSilva\"\u003e\u003e},\n    {\u003c\u003c\"name\"\u003e\u003e, \u003c\u003c\"Fabio B. Silva\"\u003e\u003e}\n],\n\nExpectations = [\n    {status, 200},\n    {content_type, \"application/json\"},\n    {json_type, [\n        {id, integer}\n    ]}\n],\n\nefrisby:post(\"/users\", Body, Expectations, ?OPTIONS).\n%% \u003e {ok, Response}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabioBatSilva%2Fefrisby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFabioBatSilva%2Fefrisby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabioBatSilva%2Fefrisby/lists"}