Make Selenium Easy

REST Assured Tutorial 68 – Request Logging In Rest Assured

As a part of End to End REST Assured Tutorial , in this post We will learn :- How to log request specification in Rest Assured?

When a request is sent to server, it consists many details like headers, cookies, body if any etc. When we get response from server, that also include headers, response body if any etc. We may need to log these information of request and response to know if correct headers, param etc are sent and received.

Rest Assured supports this logging feature. In this post, we will learn about logging Request specification.

We can log Request Specification before it is sent to server for processing. Rest Assured supports logging of Request Specification using RequestLoggingFilter class. This filter only log what is passed in Request Specification. Addition data with request like headers etc are also attached with request by HTTP Builder and HTTP Client. Those details will not be logged by Rest Assured.

RequestSpecification interface provides a method named log() that helps you to log everything or specific part of Request Specification. We have below methods of logging for Request specification:-

all() – Logs everything in the specification, including e.g. headers, cookies, body with the option to pretty-print the body if the content-type is either XML, JSON or HTML, Same job is done by a method named “everything()”.

body() – Logs only the content of the body. The body will be pretty-printed by default if content-type is either XML, JSON or HTML.

headers() – Logs only the headers.

cookies() – Logs only the cookies.

method() – Logs only request method i.e. POST, GET etc.

params() or parameters() – Logs only the parameters of the request.  It will print all query params, form params, request params and path params.

uri()– Only logs the request uri.

We will see an example:-

For demo purpose, I will add dummy headers, params and cookies. It will make API to work unexpectedly.

Rest Assured Program:-

Detailed Program:-

BDD Style program:-

You will see below output in console:-

You can clone/download example repo here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

2 thoughts on “REST Assured Tutorial 68 – Request Logging In Rest Assured

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

REST Assured Tutorial 68 – Request Logging In Rest Assured

by Amod Mahajan time to read: 4 min
%d bloggers like this: