# Extracting Variables via Utility Methods
Now, with the help of utility methods, you can extract the variables of your test case response. This functionality is helpful in extracting variables
- from any type (JSON/XML or other than JSON/XML) of test case response.
- or from response headers
- An example use case is performing token-based authentication in vREST.
# How to use:
- First define a utility method in Configuration Tab >> Utility Methods section. vREST automatically adds the following in the function context (via
this
):this.variables
This contains the variable map for global and extracted variables.this.methods
This contains the methods map. Through this, you may invoke other utility methods.this.execution
Only available if you invoke the utility methods inside theVariable Extractor
tab. This contains the API request and response details. Some important information:- If you want to access the response content then you may use
this.execution.response.content
. - If you want to access the parsed response content then you may use
this.execution.response.parsed
. - If you want to access the status code then you may use
this.execution.response.statusCode
. - And if you want to access the response headers then you may use
this.execution.response.headers
.
- If you want to access the response content then you may use
For more information about the structure of the above properties, please read our guide on Context Parameters.
You may write your utility method like below:
- Use this utility method in the variable extractor tab like this.
In the above figure, value of var1 will be extracted via utility method varExtractUtility. Here value "hello" will be passed to "userDefinedParam1" parameter and "world" will be passed to "userDefinedParam2" parameter of the utility method defined in step 1.