A rough description on how it works can be found on https://intuit.github.io/karate/.
I would like to show you an example from https://www.baeldung.com/karate-rest-api-testing
4.2. Testing the Response
Let's a write another scenario that tests that the REST endpoint returns a specific response:
Scenario: Testing the exact response of a GET endpoint
Given url 'http://localhost:8080/user/get'
When method GET
Then status 200
And match $ == {id:"1234",name:"John Smith"}
The match operation is used for the validation where ‘$' represents the response. So the above scenario checks that the response exactly matches ‘{id:”1234″,name:”John Smith”}'.
We can also check specifically for the value of the id field:
And match $.id == "1234"
The match operation can also be used to check if the response contains certain fields. This is helpful when only certain fields need to be checked or when not all response fields are known:
Scenario: Testing that GET response contains specific field
Given url 'http://localhost:8080/user/get'
When method GET
Then status 200
And match $ contains {id:"1234"}
And another example from https://aboullaite.me/karate-framework-rest-testing/
Let’s look at a final scenario that tests a POST endpoint and takes a request body:
Scenario: Create and retrieve a Product
Given path 'products'
And request { "name": "My product", "type": "Super Type", "price": 123, "shipping": 0, "upc": "041345324016", "description": "My super nice aweome product", "manufacturer": "Feo Hero", "model": "QB2400B4Z", "url": "some.url", "image": "some.image" }
When method POST
Then status 201
And def product = response
Given path '/products/'+product.id
When method GET
Then status 200
And match $ contains {id:'#(product.id)',name:'#(product.name)',type:'#(product.type)',price:#(product.price)}
Soap is a bit different, example from https://intuit.github.io/karate/#request below:
Given request read('soap-request.xml')
When soap action 'QueryUsageBalance'
Then status 200
And match response /Envelope/Body/QueryUsageBalanceResponse/Result/Error/Code == 'DAT_USAGE_1003'
And match response /Envelope/Body/QueryUsageBalanceResponse == read('expected-response.xml')