Gavel HTTP Transaction Validator

10.0.4 · maintenance · verified Wed Apr 22

Gavel is a JavaScript library designed for validating actual HTTP messages against expected HTTP messages. It provides a detailed comparison, indicating discrepancies in status codes, headers, and body content. The library supports JSON Schema validation (Draft 4, 6, and 7) for defining complex body expectations. The current stable version is 10.0.4, last released in December 2021. Its release cadence appears infrequent, with recent updates primarily focused on security patches for internal dependencies rather than new feature development. Gavel differentiates itself by offering granular validation results, pinpointing exact failures, including specific error messages and locations within JSON Schema mismatches, making it a valuable tool for API contract testing and robust HTTP interaction validation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic HTTP transaction validation, including status code, headers, and JSON body against a schema.

import gavel from 'gavel';

const expected = {
  statusCode: 200,
  headers: {
    'Content-Type': 'application/json'
  },
  bodySchema: {
    type: 'object',
    properties: {
      message: { type: 'string' }
    },
    required: ['message']
  }
};

const actual = {
  statusCode: 200,
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    message: 'Hello, world!'
  })
};

const result = gavel.validate(expected, actual);
console.log(result);

view raw JSON →