← All articles
Apache

JMeter: Extract a Value from a Response Header

JMeter can validate more than response bodies. In API tests, you may also need to capture a value returned in an HTTP response header and reuse it in a later request or assertion.

As an example, assume the API returns an ETag header:

ETag: 2666d92fa9ebf10250acdb235546f045

The goal is to extract only the header value and store it in a JMeter variable.

Configure the Regular Expression Extractor

In JMeter:

  1. Right-click the HTTP request and add Post Processors → Regular Expression Extractor.

  2. Select Main sample only.

  3. Select Response Headers as the field to check.

  4. Set Reference Name to a variable name such as eTagVariable.

  5. Set Regular Expression to:

    ETag:\s+(.+)
    

    This matches the ETag header and captures everything after the colon and whitespace as group 1.

  6. Set Template to:

    $1$
    
  7. JMeter stores the captured value in the variable named eTagVariable.

You can then reference it elsewhere in the test plan as:

${eTagVariable}

Takeaway

The Regular Expression Extractor is useful when an API returns important state in response headers rather than the body. Once extracted into a JMeter variable, the value can be reused in subsequent requests, assertions, or other test logic.

CONTINUE READING

Explore closely related architecture, integration and implementation topics.