0

I created a program to get an API response from a URL.

But for some reason it's printing it out in one long line. Is there any way to print it out the way I see it in postman? I guess what I mean is if there is a way to see the response from the API server printed out line by line instead of one long line.

    ResponseBody body = response.getBody();
    System.out.println("Response Body is: " + body.asString());

The server response is

[RemoteTestNG] detected TestNG version 6.13.1
Status code is 200
Response Body is: 
 {"request_id":"Z36ec5ee76a4788bfe83655edbbe9f0","status":"OK","data":{ONE LONG STRING OF DATA WITH NO END IN SIGHT!} 
Bekind
  • 55
  • 1
  • 13

2 Answers2

1

You can use prettyPrint method of Response class. Status you will have to print.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
  • Thank you . That worked. Can I ask you another question if you don't mind? - How do I validate required and optional fields in an API response using REST Assured ? – Bekind Mar 29 '18 at 13:55
0

(Response to comment) If your API call return JSON responses, you can use a JSON validator module.

What it does is: you provide a JSON schema, and it compares it with the response. The JSON schema syntax is defined over there: http://json-schema.org/latest/json-schema-validation.html (it looks more complex than it actually is) and here are some examples http://json-schema.org/examples.html. You can define, in your schema, if a field is "required", and also which "type" it should be (string, integer etc.) and many other things!

Here's a simple tutorial that helped me implement it with Rest-Assured: https://blog.jayway.com/2013/12/10/json-schema-validation-with-rest-assured/

agatheblues
  • 229
  • 1
  • 10