Rest Assured – How to create POST request

Create a JSON object

JSONObject requestParams = new JSONObject();
requestParams.put("AccountId", accountId);
requestParams.put("Amount", amount);

//Define baseURI
RestAssured.baseURI = apiUrl;
RestAssured.useRelaxedHTTPSValidation();

RequestSpecification request = RestAssured.given();

//Add token to request
request.header("Authorization", token);

// Add a header stating the Request body is a JSON
request.header("Content-Type", "application/json");

//Add reqeust body
request.body(requestParams.toString());

//Define Response
Response response = null;

//Store response from post request
response = request.post();

Leave a Reply

Your email address will not be published. Required fields are marked *