Selectively Discard Response body

Hello. is there a way to selectively discardResponse body? I have a test script which makes a call to retrieve a token (from the response), this token is passed as part of the request header for the service under test. which I do not need the response body…

get_token I need the response. get_stuff_from_api I do not need the response body. how can I use the options precedence to make the script sure get_token returns the body (currently set in a global options.js file) , then set there response body option to false for the functions in group()?

pseudo code…

        var res = get_token(stuff);
 		var res_json = JSON.parse(res.body);
		api_token = res_json['access_token'];
 THIS IS WHERE I NEED THE RESPONSE BODY

	// Below is the actual test case for the /account/me API endpoint
	group("get_titles_by_id", function () {
		var res = get_stuff_from_api(api_token);
		// console.log(JSON.stringify(res));

       
	});

Hello @PlayStay !

Yes, there is a way. You can set discardResponseBodies to true in the options, so basically you won’t get bodies.

export const options = {
  discardResponseBodies: true
}

After that you can selectively enable the body with setting responseType to ‘text’ as the documentation suggests Options reference :

const res = http.get('http://token.url', {responseType: 'text'});
3 Likes

Outstanding. Thanks @bandorko

1 Like