I have a long JSON body which is an array. I need to send this in the body for POST method. I am using Rest-assured. How to do it?
Asked
Active
Viewed 961 times
0
-
Please give example for more clarification – rishav prasher May 06 '19 at 07:00
1 Answers
0
If it is a static file you can have it in your code base and use the following code to call endpoint using RestAssured.
String url = "http://yourhost:port/endpoint"
File yourlargejsonfile = new File(System.getProperty("user.dir") + File.separator + "resources" + File.separator
+ "staticjsonfiles" + File.separator + "jsonfile.json");
Response response = RestAssured.given().body(yourlargejsonfile).and()
.contentType(ContentType.JSON).when().post(endpoint).then().extract().response();
If you want to have the payload to be build dynamically, I suggest you create JSONObjects/Models Classes/Plain Old Java Objects.

Vamsi Ravi
- 1,196
- 8
- 26