Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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'.