Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve JS API to retrieve request and response #1962

Closed
ptrthomas opened this issue Mar 28, 2022 · 3 comments
Closed

improve JS API to retrieve request and response #1962

ptrthomas opened this issue Mar 28, 2022 · 3 comments
Assignees

Comments

@ptrthomas
Copy link
Member

ptrthomas commented Mar 28, 2022

refer conversation here: #1861 (comment)

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'
@ptrthomas ptrthomas self-assigned this Mar 28, 2022
@ptrthomas
Copy link
Member Author

also see another use-case: https://stackoverflow.com/a/72245287/143475

@ptrthomas ptrthomas added this to the 1.3.0 milestone Aug 5, 2022
ptrthomas added a commit that referenced this issue Aug 5, 2022
the same api works in mocks as well to get the request, see updated test in this commit
a lot more useful operations are possible via the graal proxy for both request and response
the main benefit of this api is to make getting a header ignoring case easy
you can even get multi-value headers as an array
@ptrthomas
Copy link
Member Author

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'

@ptrthomas
Copy link
Member Author

1.3.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant