Installing and configuring Hoverfly
Installing and configuring Hoverfly involves a few steps to get started. Here are the general steps involved:
Check system requirements: Before you begin installing Hoverfly, it's important to ensure that your system meets the minimum requirements. For example, you may need to have a certain version of the operating system or certain dependencies installed.
Install Hoverfly: Once you've verified that your system meets the requirements, you can download and install Hoverfly. You can typically do this by downloading a pre-built binary for your operating system and architecture, or by building the software from source.
Start Hoverfly: Once Hoverfly is installed, you can start it by running the
hoverfly
command in your terminal. By default, Hoverfly will start running in "capture" mode, which means that it will start intercepting incoming requests and responses and recording them to a simulation file.Configure Hoverfly: Hoverfly can be configured in a variety of ways, depending on your needs. For example, you may need to specify which network interfaces to listen on, or which ports to use for incoming and outgoing traffic. You may also need to configure TLS certificates or specify authentication credentials.
Test Hoverfly: Once Hoverfly is installed and configured, you can test it by sending requests to your application and verifying that the responses are being intercepted and recorded correctly. You can also use the Hoverfly UI or API to view and modify the simulation file.
Demo
Running the Hoverfly server
mail2@sm15 MINGW64 /c/hoverfly $ hoverctl start Hoverfly is now running +------------+------+ | admin-port | 8888 | | proxy-port | 8500 | +------------+------+
Capturing Requests and Responses
mail2@sm15 MINGW64 /c/hoverfly $ hoverctl mode capture Hoverfly has been set to capture mode
mail2@sm15 MINGW64 /c/hoverfly $ hoverctl export firstRequest.json Successfully exported simulation to firstRequest.json
{"data": {"pairs": [{"request": {"path": [{"matcher": "exact","value": "/search"}],"method": [{"matcher": "exact","value": "GET"}],"destination": [{"matcher": "exact","value": "universities.hipolabs.com"}],"scheme": [{"matcher": "exact","value": "http"}],"body": [{"matcher": "exact","value": ""}],"query": {"country": [{"matcher": "exact","value": "Monaco"}]}},"response": {"status": 200,"body": "[{\"web_pages\": [\"http://www.riviera.fr/usehome.htm\"], \"state-province\": null, \"alpha_two_code\": \"MC\", \"name\": \"University of Southern Europe (Monaco Business School)\", \"country\": \"Monaco\", \"domains\": [\"riviera.fr\"]}]","encodedBody": false,"headers": {"Access-Control-Allow-Origin": ["*"],"Connection": ["keep-alive"],"Content-Length": ["216"],"Content-Type": ["application/json"],"Date": ["Mon, 16 Jan 2023 19:14:16 GMT"],"Hoverfly": ["Was-Here"],"Server": ["nginx/1.14.0"]},"templated": false}}],"globalActions": {"delays": [],"delaysLogNormal": []}},"meta": {"schemaVersion": "v5.1","hoverflyVersion": "v1.3.5","timeExported": "2023-01-16T14:19:27-05:00"}}
Playing Back the Recorded Requests
mail2@sm15 MINGW64 /c/hoverfly $ hoverctl mode simulate Hoverfly has been set to simulate mode with a matching strategy of 'strongest'
"body": "[{\"web_pages\": [\"http://www.riviera.fr/usehome.htm\"], \"state-province\": null, \"alpha_two_code\": \"CC\", \"name\": \"University of Southern Europe (Monaco Business School)\", \"country\": \"Monaco\", \"domains\": [\"riviera.fr\"]}]",
mail2@sm15 MINGW64 /c/hoverfly $ hoverctl import firstRequest.json Successfully imported simulation from firstRequest.json
Stopping the server
mail2@sm15 MINGW64 /c/hoverfly $ hoverctl stop Hoverfly has been stopped
Leave a Comment