{"id":15284325,"url":"https://github.com/rschultheis/hatt","last_synced_at":"2026-05-15T22:37:06.904Z","repository":{"id":56876072,"uuid":"91092877","full_name":"rschultheis/hatt","owner":"rschultheis","description":"HTTP API Testing Tool","archived":false,"fork":false,"pushed_at":"2019-08-09T19:02:38.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T11:07:21.583Z","etag":null,"topics":["api-testing","automated-testing","faraday","http-client","minitest","quality","rest-api","rspec","testing"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/rschultheis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-12T13:11:20.000Z","updated_at":"2018-07-05T15:51:39.000Z","dependencies_parsed_at":"2022-08-20T22:00:44.362Z","dependency_job_id":null,"html_url":"https://github.com/rschultheis/hatt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rschultheis%2Fhatt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rschultheis%2Fhatt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rschultheis%2Fhatt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rschultheis%2Fhatt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rschultheis","download_url":"https://codeload.github.com/rschultheis/hatt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245138291,"owners_count":20566911,"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":["api-testing","automated-testing","faraday","http-client","minitest","quality","rest-api","rspec","testing"],"created_at":"2024-09-30T14:53:34.954Z","updated_at":"2026-05-15T22:37:01.857Z","avatar_url":"https://github.com/rschultheis.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HATT (HTTP API Testing Tool)\n\nHATT is a tool, and a pattern, for testing HTTP APIs (RESTful or otherwise).  It can be used to\nconstruct fully automated tests, and also provides support for simple manual testing.\n\nHATT is a Ruby tool and gem.  It leverages the full power of Ruby.  That said, HATT should be usable by those\nwith little familiarity of Ruby, but some knowledge of scripting languages in general.  HATT works with standard\nRuby testing frameworks like RSpec and MiniTest.\n\n## Basic testing features\n\n* Easily configure and interact with one or more HTTP services (RESTful services).\n* \"Point\" tests and requests at various deployment environments (eg, QA, Staging, Production)\n* Using RSpec or MiniTest or any other testing framework, construct fully automated tests.\n* Easily define a \"DSL\", or domain-specific-language for interacting with your API in your\n  own terms.  This allows for writing self-documenting, easy to understand tests.\n* Easily integrates into popular Continuos Integration tools like Jenkins.  This means\n  your tests can run on a central server where all team members can access them.\n\n\n## Short Example\n\nThe code for this entire example lives at [https://github.com/rschultheis/hatt_example].\nLooking through that project shows examples of using nearly every hatt feature,\nand examples of many kinds of tests and assertions against APIs.\n\nThis example is based on a free API: OpenWeatherMap.  While the API is free, one must sign-up for an API key here:\n[http://openweathermap.org/appid].  Keep your API key handy you will need it soon...\n\n### Configure HATT, and setup a simple DSL method\n\n#### install hatt\n\n    gem install hatt\n\n#### make a project directory\n\n    mkdir open_weather_map_api_test_suite\n    cd open_weather_map_api_test_suite\n\n#### Make a file called 'hatt.yml' with these contents:\n\n    hatt_services:\n      # shothand of owm for \"open weather map api\"\n      owm:\n        url: http://api.openweathermap.org\n\n#### Put our API key into hatt.secret.yml\n\nWe need a special place to put our API key. For that make a file called hatt.secret.yml.  This is a file that is generally not to be checked into source control, it should be used for configuring any secrets (like API keys or passwords). Put this one line into the file:\n\n    owm_app_id: \u003cyour api key here\u003e\n\n#### make the hattdsl directory:\n\n    mkdir hattdsl\n\n#### add method for checking weather to hattdsl/open_weather_map_hattdsl.rb\n\n    def weather_for city\n      owm.get \"/data/2.5/weather?q=#{URI.encode(city)}\u0026APPID=#{appid}\"\n    end\n\n    def appid\n      hatt_configuration['owm_app_id']\n    end\n\n#### Call it from the cmd line:\n\n    hatt -v weather_for \"Pleasantville, NY\"\n\nAnd that returns something like this:\n\n    ... \u003cdetailed logging showing full request / response\u003e\n    D: [06/14/17 17:07:53][hatt] - HATT method 'weather_for' returned:\n    {\"coord\"=\u003e{\"lon\"=\u003e-73.79, \"lat\"=\u003e41.13}, \"weather\"=\u003e[{\"id\"=\u003e800, \"main\"=\u003e\"Clear\", \"description\"=\u003e\"clear sky\", \"icon\"=\u003e\"01d\"}], \"base\"=\u003e\"stations\", \"main\"=\u003e{\"temp\"=\u003e299.68, \"pressure\"=\u003e1014, \"humidity\"=\u003e39, \"temp_min\"=\u003e296.15, \"temp_max\"=\u003e303.15}, \"visibility\"=\u003e16093, \"wind\"=\u003e{\"speed\"=\u003e4.1, \"deg\"=\u003e190}, \"clouds\"=\u003e{\"all\"=\u003e1}, \"dt\"=\u003e1497480900, \"sys\"=\u003e{\"type\"=\u003e1, \"id\"=\u003e1980, \"message\"=\u003e0.0057, \"country\"=\u003e\"US\", \"sunrise\"=\u003e1497432119, \"sunset\"=\u003e1497486575}, \"id\"=\u003e5131757, \"name\"=\u003e\"Pleasantville\", \"cod\"=\u003e200}\n\n\nSo, at this point we are able to call the API, and see the full details of the request and response.  We can manually\ntest a lot at this point.  But HATT can do more....\n\n\n### Make a ruby script, that uses the hattdsl:\n\n#### Make a file called temperatures.rb with this in it:\n\n    [\n      'New York, NY',\n      'Toronto, Canada',\n      'Paris, France',\n      'Tokyo, Japan',\n      'Sydney, Australia',\n    ].each do |city|\n      weather = weather_for city\n      kelvin = weather['main']['temp']\n      celcius = (kelvin - 273.15).round\n      puts \"#{city}: #{celcius} celcius\"\n    end\n\n#### And then run the hatt script like so:\n\n    hatt -q -f temperatures.rb\n\nAnd get this nice output (-q supresses all the detailed request/response logging, leaving only the puts in the script):\n\n    New York, NY: 18 celcius\n    Toronto, Canada: 7 celcius\n    Paris, France: 18 celcius\n    Tokyo, Japan: 16 celcius\n    Sydney, Australia: 14 celcius\n\n\n### Make an automated test\n\nUsing the included Hatt::Mixin and Hatt::SingletonMixin module, testing an api becomes easy.  Lets setup a simple RSpec example here.\n\n#### Install rspec:\n\n    gem install rspec\n\n#### Create the spec folder:\n\n    mkdir spec\n\n#### Setup spec/spec_helper.rb with these contents to :\n\n    require 'hatt'\n\n    RSpec.configure do |config|\n\n      config.include Hatt::SingletonMixin\n\n      config.before(:all) do\n        hatt_initialize\n      end\n    end\n\n#### Setup spec/weather_spec.rb with contents like:\n\n    require 'spec_helper'\n    describe \"getting weather reports\" do\n      it \"should know the weather for New York City\" do\n        response = weather_for 'New York, NY'\n        expected_items = ['temp', 'temp_min', 'temp_max', 'humidity', 'pressure']\n        # the actual assertions here\n        expect(response['main'].keys).to include(*expected_items)\n        # the temp is in kelvin, so it looks kinda wierd\n        expect(response['main']['temp']).to be_between(100, 400)\n      end\n    end\n\n#### Run it:\n\n    rspec\n\nAnd get back:\n\n    ... \u003cdetailed logging showing all request response details\u003e ...\n\n    1 example, 0 failures\n\n\n\nAnd THAT is the basic way to use HATT to test an API.\n\nFor more information, and more detailed examples of how to do nearly anything using HATT, see the example\nproject: [https://github.com/rschultheis/hatt_example]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frschultheis%2Fhatt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frschultheis%2Fhatt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frschultheis%2Fhatt/lists"}