Contract testing CLI — verify HTTP APIs against Gherkin feature files.
SpecBridge lets you describe the expected behaviour of an HTTP API in plain-English Gherkin (.feature) files and then verify a live service against those contracts from the command line.
- Node.js ≥ 18
npm install -g @ksz54213/specbridgespecbridge verify -f <path-to-feature> -u <base-url>
| Option | Alias | Required | Description |
|---|---|---|---|
--file |
-f |
✅ | Path to the .feature contract file |
--url |
-u |
✅ | Base URL of the service to test (e.g. http://localhost:3000) |
Contracts are written in Gherkin and stored as .feature files.
Each Scenario maps to one API call and a set of assertions.
| Step | Description |
|---|---|
When I send a "METHOD" request to "/path" |
HTTP request (GET, POST, PUT, DELETE, …) |
And the request body is: + doc-string |
JSON request body |
Then the response status should be <code> |
Assert HTTP status code |
Then the response body should be: + doc-string |
Assert exact JSON response (key-by-key) |
Then the response body should contain field "key" with value "val" |
Assert a single field value |
A scenario must include at least one
Whenstep and oneThenstatus step to be executed. Scenarios missing these are skipped with a warning.
The example-api/ directory contains a small Node.js server and example.feature provides its contract.
cd example-api
npm start
# Example API running at http://localhost:3000From the project root:
specbridge verify -f example.feature -u http://localhost:3000✅ Scenario: Health check endpoint
GET http://localhost:3000/api/health
✅ Scenario: Get user by ID
GET http://localhost:3000/api/users/1
✅ Scenario: Create a new user
POST http://localhost:3000/api/users
────────────────────────────────
Results: 3 passed, 0 failed
────────────────────────────────
Feature: API Contract Verification
Scenario: Health check endpoint
When I send a "GET" request to "/api/health"
Then the response status should be 200
Then the response body should contain field "status" with value "ok"
Scenario: Get user by ID
When I send a "GET" request to "/api/users/1"
Then the response status should be 200
Then the response body should be:
"""
{ "id": 1, "name": "John" }
"""
Scenario: Create a new user
When I send a "POST" request to "/api/users"
And the request body is:
"""
{ "name": "Alice", "email": "alice@example.com" }
"""
Then the response status should be 201
Then the response body should contain field "name" with value "Alice"| Method | Path | Description |
|---|---|---|
GET |
/api/health |
Health check — returns { "status": "ok" } |
GET |
/api/users/:id |
Fetch a user by ID |
POST |
/api/users |
Create a new user (requires name in body) |
| Code | Meaning |
|---|---|
0 |
All scenarios passed |
1 |
One or more scenarios failed, or the feature file was not found / could not be parsed |
npm testMIT