Skip to main content

Adapters

What are Adapters?

Adapters let you perform custom modifications to a request or response during execution.

An adapter takes the form of a command that can be configured to run at specific stages.

Configuration

specmatic.yaml
version: 3
dependencies:
data:
adapters:
post_specmatic_response_processor: python post_specmatic_response_processor.py
pre_specmatic_request_processor: python pre_specmatic_request_processor.py
pre_specmatic_response_processor: python pre_specmatic_response_processor.py

How Adapters Work

As an example, in the above snippet, pre_specmatic_request_processor is an adapter name. Specmatic executes the configured command and passes request data through STDIN.

Sample input to the adapter (STDIN):

{
"http-request": {
"method": "POST",
"path": "/api/data",
"headers": {
"Content-Type": "application/json"
},
"body": {
"data": "eyJrZXkiOiAidmFsdWUifQ=="
}
}
}

Sample output from the adapter (STDOUT):

{
"http-request": {
"method": "POST",
"path": "/api/data",
"headers": {
"Content-Type": "application/json"
},
"body": {
"data": {
"key": "value"
}
}
}
}

Read more about adapters here.

Note: Specmatic also supports specification adaptors via Overlays. Read more about Specmatic's support for Overlays here.