Gavel
Behavior spec for Gavel, validator of HTTP transactions
 
Gavel - Validator of HTTP Transactions
What is Gavel?
Gavel detects important differences between actual and expected HTTP transactions (HTTP request and response pairs). Gavel also decides whether the actual HTTP transaction is valid or not.
Input:
- Expected HTTP request and corresponding response
- Actual HTTP request and corresponding response
Output:
- Validation verdict (boolean) or validation result (complex information about what's different)
Gavel is useful specifically in testing HTTP APIs. It enables [specification by example][] and [BDD][] approach. The most prominent project built on top of Gavel is [Dredd][], framework which tests HTTP APIs against their documentation.
Implementations
- [JavaScript][Gavel.js] 
- Didn't find your favorite language? Add a new one!
Command-line Interface
Gavel's CLI works well together with curl --trace and the curl-trace-parser utility:
$ curl --trace - http://httpbin.org/ip | curl-trace-parser > expected
$ curl --trace - http://httpbin.org/ip | curl-trace-parser > actual
$ cat actual | gavel expected
$ echo $?
0To learn more about the CLI, head to the Command-line interface topic.
Expectations
See following paragraphs for a basic overview of how Gavel works. To learn more about the expectations, head to the General validation behavior topic.
Response status
Status code of the expected response must be the same as the one in the actual response.
Request and response headers
- All expected request headers must be present in the actual request. The same applies for responses.
- Names of headers are validated in case-insensitive way.
- Only values of headers significant for content negotiation are validated.
- All other header values can differ.
For more information see the respective topic.
Request and response body
- If the body is JSON, Gavel validates only its structure.
- Bodies in any other format are validated as plain text.
- If Gavel is provided with JSON Schema, it overrides the default validation behavior.
[Dredd]: https://github.com/apiaryio/dredd [Gavel.js]: https://github.com/apiaryio/gavel.js [specification by example]: http://en.wikipedia.org/wiki/Specification_by_example [BDD]: http://en.wikipedia.org/wiki/Behavior-driven_development
In this section
Source: features/README.md at v1.2.0, Gavel (MIT license).