Master CLI API Testing: The Complete Developer Guide

February 5, 20269 min readTutorial

As a backend developer, you spend most of your time in the terminal. You build APIs, run migrations, check logs, and deploy services—all from the command line. So why switch to a GUI tool just to test your endpoints?

CLI-based API testing keeps you in your natural workflow. No context switching. No mouse dependency. Just fast, efficient, keyboard-driven testing that integrates seamlessly with your development process.

SiroPHP is a lightweight PHP API framework that includes native CLI testing tools. With features like auto-authentication, request history, and automation scripts, you can test APIs faster than ever before.

1. Why Test APIs from CLI?

Backend developers live in the terminal. It's where we feel most productive. CLI-based API testing respects this workflow by keeping everything in one place.

Benefits of CLI Testing:

  • No context switching - Stay in your terminal
  • Keyboard-driven - Faster than clicking through UI
  • Scriptable - Automate repetitive tests
  • Version control friendly - Save test commands in git
  • CI/CD integration - Easy to run in pipelines
  • Lightweight - No heavy GUI application

💡 Pro Tip:If you're already comfortable with curl or httpie, CLI testing will feel natural. SiroPHP makes it even easier with auto-authentication and built-in helpers.

2. Basic CLI Testing Commands

Testing an API endpoint from the command line is straightforward. Here are the essential commands you'll use daily.

GET Requests

# Simple GET request
php siro api:test GET /api/users

# With query parameters
php siro api:test GET /api/users?page=2&limit=10

# With custom headers
php siro api:test GET /api/data --header="X-API-Key: abc123"

POST Requests

# POST with data
php siro api:test POST /api/users name="John Doe" email="john@example.com"

# POST with JSON body
php siro api:test POST /api/products   name="Laptop"   price=999   category="electronics"

PUT/PATCH/DELETE

# Update resource
php siro api:test PUT /api/users/123 name="Jane Doe"

# Partial update
php siro api:test PATCH /api/users/123 email="jane@example.com"

# Delete resource
php siro api:test DELETE /api/users/123

3. Auto-Authentication (Game Changer)

One of the biggest pain points in API testing is managing authentication tokens. Traditional workflows require you to:

  1. Login manually
  2. Copy the token from response
  3. Paste it into every subsequent request
  4. Repeat when token expires

SiroPHP eliminates this friction with auto-authentication. Login once, and the token is saved automatically for future requests.

How It Works

# Step 1: Login and save token as "admin"
php siro api:test POST /auth/login   email=admin@example.com   password=secret123   --as=admin

# Output:
✓ Login successful
✓ Token saved as "admin"

# Step 2: Use saved token automatically
php siro api:test GET /api/users --as=admin
php siro api:test POST /api/products name="Phone" --as=admin
php siro api:test DELETE /api/users/456 --as=admin

# All requests above automatically include the saved token!

Multiple User Sessions

You can maintain multiple authenticated sessions simultaneously—perfect for testing role-based access control.

# Login as different users
php siro api:test POST /auth/login email=admin@test.com password=pass --as=admin
php siro api:test POST /auth/login email=user@test.com password=pass --as=user
php siro api:test POST /auth/login email=mod@test.com password=pass --as=moderator

# Test with different roles
php siro api:test GET /admin/dashboard --as=admin       # ✓ Access granted
php siro api:test GET /admin/dashboard --as=user        # ✗ Access denied
php siro api:test GET /admin/dashboard --as=moderator   # ✓ Access granted

Time Saved:Auto-authentication saves ~2-3 minutes per testing session. Over a week, that's 1-2 hours of productivity regained.

4. Request History & Reusability

CLI testing isn't just about running commands—it's about building a reusable testing workflow. SiroPHP tracks your request history and lets you save frequently used commands.

View Request History

# Show last 20 requests
php siro api:test --history

# Output:
[2026-02-05 14:32:15] GET    /api/users          --as=admin  (200 OK, 45ms)
[2026-02-05 14:31:42] POST   /api/products       --as=admin  (201 Created, 67ms)
[2026-02-05 14:30:18] GET    /api/orders         --as=user   (200 OK, 38ms)
[2026-02-05 14:29:55] POST   /auth/login         --as=admin  (200 OK, 120ms)

Save & Reuse Commands

# Save a complex request
php siro api:test POST /api/orders   user_id=123   product_id=456   quantity=2   --save=create-order

# Reuse anytime
php siro api:test --run=create-order

# Update saved command
php siro api:test POST /api/orders   user_id=123   product_id=789   quantity=1   --save=create-order --overwrite

5. Automation & Scripting

The real power of CLI testing emerges when you automate repetitive workflows. Create test scripts, integrate with CI/CD, and build comprehensive test suites.

Test Script Example

#!/bin/bash
# test-api.sh - Automated API test suite

echo "🧪 Running API Test Suite..."

# Login
echo "→ Logging in..."
php siro api:test POST /auth/login   email=test@example.com   password=test123   --as=testuser

# Test CRUD operations
echo "→ Testing user creation..."
php siro api:test POST /api/users   name="Test User"   email="testuser@example.com"   --as=testuser

echo "→ Testing user retrieval..."
php siro api:test GET /api/users --as=testuser

echo "→ Testing user update..."
php siro api:test PUT /api/users/1   name="Updated Name"   --as=testuser

echo "→ Testing user deletion..."
php siro api:test DELETE /api/users/1 --as=testuser

echo "✅ All tests passed!"

CI/CD Integration

Integrate CLI tests into your deployment pipeline to catch issues before they reach production.

# .github/workflows/test.yml
name: API Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v2
      
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.2'
      
      - name: Install dependencies
        run: composer install
      
      - name: Start server
        run: php siro serve &
      
      - name: Run API tests
        run: bash test-api.sh

6. Advanced Tips & Best Practices

Tip 1: Use Environment Variables

# Set base URL in .env
API_BASE_URL=http://localhost:8080

# Use in tests
php siro api:test GET /api/users --base=$API_BASE_URL

Tip 2: Chain Commands

# Run multiple tests in sequence
php siro api:test GET /api/users --as=admin && php siro api:test GET /api/products --as=admin && php siro api:test GET /api/orders --as=admin

Tip 3: Custom Response Formatting

# Pretty-print JSON response
php siro api:test GET /api/users --as=admin | jq

# Extract specific field
php siro api:test GET /api/users/1 --as=admin | jq '.data.email'

Tip 4: Performance Testing

# Measure response time
time php siro api:test GET /api/users --as=admin

# Run load test (using parallel)
seq 1 100 | parallel -j 10 php siro api:test GET /api/users --as=admin

Conclusion

CLI-based API testing isn't just about avoiding GUI tools—it's about embracing a workflow that aligns with how backend developers naturally work. By keeping everything in the terminal, you reduce context switching, increase speed, and enable automation.

With SiroPHP's built-in CLI testing tools, you get:

  • Auto-authentication (no more manual token management)
  • Request history and reusability
  • Automation-friendly commands
  • Seamless integration with your existing workflow

Start testing APIs from your terminal today. Your future self will thank you for the time saved and the improved productivity.

Ready to Try CLI Testing?

Install SiroPHP and experience keyboard-driven API testing