0

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?

Dhruv Bhatnagar
  • 121
  • 5
  • 17

1 Answers1

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