Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send form-data in api using Rest-assured

I want to send below as a form-data in API Body for a PUT request:

  1. Upload a file(KEY) with "Error.png"(VALUE)
  2. Send text, "MyName"(KEY) with false(VALUE)

How to do this using REST-Assured

Attached is the screenshot Form-Data Image

like image 839
D Bhatnagar Avatar asked Jan 15 '18 11:01

D Bhatnagar


People also ask

How do I make a POST request in rest assured?

How to make a POST Request using Rest Assured? Step 1: Create a Request pointing to the Service Endpoint. Step 2: Create a JSON request which contains all the fields. Step 3: Add JSON body in the request and send the Request. Step 4: Validate the Response. Once we get the response back, all we have ...

How to reach amounts in the API using rest assured?

Step 1) The amount field is within an array with Key “statements” which is in turn in the list with key “result” Step 2) Rest Assured, provides a mechanism to reach the values in the API using “path” Step 3) The path to reach amounts is “result.statements.AMOUNT”.

How to get the status code of a rest assured request?

Step 1) Create a method called getResponseStatus () Step 2) Use the same request structure used above. Copy and paste it. Step 3) Instead of logging it, we use the 'getStatusCode' inbuilt method of Rest Assured to fetch the status code value.

How to send Form-data in API body for put request?

I want to send below as a form-data in API Body for a PUT request: You need to set desired content type i.e "multipart/form-data" and add the multipart request specs to the request. Eg. given () .contentType ("multipart/form-data") .multiPart ("file", "filename") .multiPart ("key", "value") .when () .put (endpoint);


1 Answers

You need to set desired content type i.e "multipart/form-data" and add the multipart request specs to the request. Eg.

        given()
            .contentType("multipart/form-data")
            .multiPart("file", "filename")
            .multiPart("key", "value")
            .when()
            .put(endpoint);
like image 179
rohit.jaryal Avatar answered Oct 17 '22 02:10

rohit.jaryal