Ask Your Question
1

How can we replace or modify the value of the request header in karate mocking?

asked 2023-07-20 21:00:04 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-20 21:19:01 +0000

pufferfish gravatar image

We can replace or modify the value of the request header in Karate mocking by using the 'header' keyword.

Here's an example:

Scenario: Modify request header in Karate mocking

Given def responseHeaders = { 'Content-Type': 'application/json' } And def requestBody = { 'name': 'John Doe', 'age': 30 } And replace requestHeaders.Authorization = 'Bearer token' And header Authorization = 'Modified token' When path '/users' And method post And request requestBody Then status 200 And responseHeaders responseHeaders

In the above example, we first define the response headers and request body. Then we replace the value of the 'Authorization' header with 'Bearer token'. Finally, we use the 'header' keyword to modify the value of the 'Authorization' header to 'Modified token'.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-20 21:00:04 +0000

Seen: 19 times

Last updated: Jul 20 '23