Here is Dev rest client POST request sudocode
public ResponseDTO upload(@RequestParam("metadata") String metaData,
@RequestParam(name="file" , required=false) MultipartFile[] multiPartFiles)
I am trying to create a POST request using restassured. Below is my code of step definitation
public void havePostCall(String endpoint) {
String url = be.getBaseUrl()+endpoint;
FileInputStream fisFile = new FileInputStream(new File("Path of the json file"));
String reqPayload = IOUtils.toString(fisFile,"UTF-8");
Response rs = RestAssured.given().header("Authorization","value of token")
.queryParam("metadata",reqPayload).when().post(url).then().assertThat().statusCode(200)
.extract()
.response ()
System.out.print("Response is ==" + rs.asString())
}
as we can see dev rest client upload method is expecting Request Param in the POST Request and in my Rest assured code I am passing the same but I still keep on getting BAD request. When I check with dev they say pass body as a Request Param. Can some one please help me what wrong I am doing in my step definiation code? Strugging quite long time any help much appreciated.
This has been resolved. The issue was the key which is passing in queryParam
.
Response rs = RestAssured.given().header("Authorization","value of token")
.queryParam("metaData",reqPayload).when().post(url).then().assertThat().statusCode(200)
.extract()
.response ()
System.out.print("Response is ==" + rs.asString())