Skip to main content

Request Logging in REST Assured

If you want to identify some issue in Request you can use request logging. Request logging can be done for headers, cookies, uri, request method, parameters as well as body. You can log each thing separately or all at once using .all().

Example:

public class DummyRestAPIExample 
{
	@BeforeClass
	public void setup()
	{
		RestAssured.baseURI = "http://dummy.restapiexample.com";
		RestAssured.basePath = "/api/v1";
	}
	
	@Test
	public void postMethodExample()
	{
		Response res = 
		given()
			.log()
//			.cookies()
//			.headers()
//			.body()
//			.parameters()
//			.method()
//			.uri()
			.all()
			.body("{" + 
					"\"name\":\"test\",\n" + 
					"\"salary\":\"123\",\n" + 
					"\"age\":\"23\"\n" + 
					"}")
		.when()
			.post("/create");
		
		System.out.println(res.body());
			
	}
}

Remove the comment to print log for each individual entity like cookies, headers etc. .all() will print logs for all.

Submitted by tgoswami on September 2, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.