karate
karate copied to clipboard
improve JS API to retrieve request and response
refer conversation here: https://github.com/karatelabs/karate/pull/1861#issuecomment-1080562695
proposing the following for a start:
# get single header
* match karate.response.header('foo') == 'bar'
# get all header values by key
* match karate.response.headers('foo') == ['bar']
# same pattern for request
* match karate.request.header('foo') == 'bar'
# in future can add some helpers:
* match karate.response.body == 'success'
* match karate.request.method == 'PUT'
also see another use-case: https://stackoverflow.com/a/72245287/143475
cc @fscarlato - this is implemented. here are the new API-s possible:
karate.response.header('some-header')
- gets the header value ignoring case
karate.response.headerValues('some-header')
gets all values for the header (ignoring-case) as a string-array,
the same works for karate.request
. the great thing is that it can be used even in mock routing expressions:
Scenario: pathMatches('/v1/headers') && karate.request.header('foo') == 'bar'
1.3.0 released