API Testing and Monitoring with Hurl: A Lightweight Alternative to Postman

Development tutorial - IT technology blog
Development tutorial - IT technology blog

Run Your First Test in 2 Minutes

The feeling of waiting 30 seconds for Postman to start just to check a simple endpoint is truly frustrating. I switched to Hurl. It’s a command-line tool (CLI) that lets you write API test scripts in plain text files, making it much faster and lighter for building ‘blazing fast’ REST APIs.

To get started, install Hurl. On macOS, it only takes one command:

# macOS
brew install hurl

# Linux (Ubuntu/Debian)
curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/4.3.0/hurl_4.3.0_amd64.deb
sudo dpkg -i hurl_4.3.0_amd64.deb

Now, create a test.hurl file to test a sample API:

GET https://jsonplaceholder.typicode.com/posts/1

HTTP 200
[Asserts]
jsonpath "$.id" == 1
jsonpath "$.title" contains "sunt aut facere"

Run the following command to execute the test:

hurl --test test.hurl

The results appear instantly. No bulky UI needed—you now have a professional test suite.

Why Choose Hurl Over Postman?

I once managed a system with over 100 endpoints. During that time, using Postman revealed three critical drawbacks that exhausted my team:

  • The Git Conflict Nightmare: Postman’s JSON files are extremely hard to read during code reviews. If two people modify a collection simultaneously, merging becomes a disaster. Hurl uses plain text, making diffs perfectly clean.
  • Significant Performance Difference: Postman often consumes 500MB to 1GB of RAM. Hurl is written in Rust and uses less than 10MB of RAM while running.
  • Ultra-Compact CI/CD Integration: You don’t need to install Node.js or Newman. Hurl is a single binary file of about 5MB, making it ideal for minimalist Docker images.

Hurl Syntax: Intuitive and Powerful

Hurl does more than just send requests. It allows you to perform detailed assertions on the returned data.

1. Sending Data (POST Request)

Creating new data is done very naturally:

POST https://api.itfromzero.com/v1/users
{
  "name": "John Doe",
  "email": "[email protected]"
}

HTTP 201
[Asserts]
jsonpath "$.message" == "User created"

2. Speed Control and Headers

You can enforce performance standards directly in the test file. For example, the API must respond in under 500ms:

GET https://api.itfromzero.com/v1/health

HTTP 200
[Asserts]
duration < 500
header "Content-Type" == "application/json; charset=utf-8"

Handling Complex Scenarios: Request Chaining

In practice, you often need to log in to get a token before calling the main API. Hurl handles this flow smoothly using variables.

# Step 1: Login and save the Token
POST https://api.example.com/login
{
  "username": "admin",
  "password": "secret"
}

HTTP 200
[Captures]
token: jsonpath "$.access_token"

# Step 2: Use the token for the next request
GET https://api.example.com/profile
Authorization: Bearer {{token}}

HTTP 200
[Asserts]
jsonpath "$.username" == "admin"

To run across multiple environments (Dev/Staging), simply use an env.properties file and the --variables-file flag. This approach separates data from the test scenarios.

Automation with GitHub Actions

Instead of paying for third-party monitoring services, you can turn GitHub Actions into a free API monitoring system for your microservices architecture. Every time you push code, Hurl will automatically check the entire system.

name: API Monitoring
on: [push, schedule: {cron: "*/5 * * * *"}]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Hurl
        run: |
          curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/4.3.0/hurl_4.3.0_amd64.deb
          sudo dpkg -i hurl_4.3.0_amd64.deb
      - name: Run Tests
        run: hurl --test tests/*.hurl

Real-world Tips

After applying Hurl to several projects, I’ve gathered three small tips:

  1. File Structure: Don’t put everything in a single file. Split them by feature, such as auth.hurl or payment.hurl, for easier management.
  2. Leverage HTML Reports: Use the --report-html report/ flag on CI. When a test fails, you’ll have a visual webpage to see exactly where the error occurred.
  3. Don’t Overuse It: Hurl is great for automation, but if you need to explore a new API for the first time, GUI tools like Postman or Insomnia still have their place.

Hurl is a small but mighty tool. It professionalizes the development process by integrating test scenarios into a standard source control workflow, much like managing a full-stack TypeScript monorepo.

Share: