Looks like your server is expecting a request body but you're sending the data as query parameters. If I understand it correctly you want to send your data as JSON. The easiest way to do this is using this approach:
Map<String, Object> map = new HashMap<>();
map.put("name", "Test12");
map.put("title", "Test127123");
map.put("contactEmail", "[email protected]");
map.put("description", "testing purpose");
ResponseBody body =
given().
accept(ContentType.JSON).
contentType(ContentType.JSON).
header("userid", "131987").
body(map).
when().
post("").
thenReturn().body();
Answer from Johan on Stack OverflowTOOLSQA
toolsqa.com โบ rest-assured โบ post-request-using-rest-assured
Understanding POST request method using Rest Assured
February 7, 2022 - Post request mostly results in creating a new record in the database. It can also update the existing record in the database. Rest Assured uses a post () method to make HTTP POST requests.
Top answer 1 of 4
13
Looks like your server is expecting a request body but you're sending the data as query parameters. If I understand it correctly you want to send your data as JSON. The easiest way to do this is using this approach:
Map<String, Object> map = new HashMap<>();
map.put("name", "Test12");
map.put("title", "Test127123");
map.put("contactEmail", "[email protected]");
map.put("description", "testing purpose");
ResponseBody body =
given().
accept(ContentType.JSON).
contentType(ContentType.JSON).
header("userid", "131987").
body(map).
when().
post("").
thenReturn().body();
2 of 4
1
Check the fully qualified path for POST URI. The body for the post call is missing, which is mandatory. ur call should be like:
Response _res = requestspec.body(jsonObject).post(url);
Then you can perform operations on Response.
Videos
38:09
23. Automate POST Requests with Rest Assured | Rest Assured Tutorial ...
11:59
How to Upload File in Rest Assured API Automation Testing Tutorial ...
01:30:11
REST Assured API Testing Tutorial Chapter-01| Getting Started | ...
01:00:27
Session 2: API Testing | RestAssured | Creating Post Request Payloads ...
14:29
Rest-Assured : How to perform POST Method in RestAssured : Tutorial ...
06:48
Part 7 - Rest Assured -POST Request- Pass Request Body using File, ...
Rest-assured
rest-assured.io
REST Assured
2026-01-16: REST Assured 5.5.7 is released with backported support for Spring framework 7 MockMvc support.
GitHub
github.com โบ rest-assured โบ rest-assured โบ wiki โบ usage
Usage ยท rest-assured/rest-assured Wiki ยท GitHub
In case of GET query parameters will automatically be used and in case of POST form parameters will be used. In some cases it's however important to separate between form and query parameters in a PUT or POST.
Author ย rest-assured
TOOLSQA
toolsqa.com โบ rest-assured โบ rest-assured-examples
Understanding Rest Assured Examples - GET, POST, PUT, DELETE
April 8, 2022 - Here we post a request to BookStore and get the response from the API. The HTTP PUT request either update a resource or substitutes the representation of the target resource with the full JSON request payload. For a detailed discussion on HTTP PUT requests, visit PUT Request using Rest Assured.
Naveenautomationlabs
naveenautomationlabs.com โบ http-post-method-using-restassured
HTTP POST Method Using RestAssured
package com.restassured.tests; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; import io.restassured.http.ContentType; import static io.restassured.RestAssured.given; /** * * @author Mandeep kaur * */ public class SamplePostRestTest { @Test public void createUser_whenSuccess() { JSONArray jsonArray = new JSONArray(); jsonArray.put("Employee"); JSONObject jo = new JSONObject(); jo.put("name", "john"); jo.put("age", "22"); jo.put("city", "chicago"); jsonArray.put(jo); given().log().all().header("authorization", "Bearer 0431655cfe7ba40a791e0ce32d83ad33363348919c11627f409a3228f205e15f23") .accept(ContentType.JSON) .contentType("application/json") .and() .body(jsonArray.toString()) .post("https://gorest.co.in/public-api/users") //hit the post end point .thenReturn().asString(); } }
How to do in Java
howtodoinjava.com โบ home โบ java libraries โบ rest-assured http post and put examples
REST-assured HTTP POST and PUT Examples
August 22, 2022 - User user = new User("lokesh", "admin@howtodoinjava.com"); given() .body(user) .contentType("application/json") .when() .post("/users") .then() .statusCode(equalTo(201)); The User is a simple POJO without any annotation. public class User { private String name; private String email; //Setters, getters and constructors } To customize the serialization and deserialization, REST-assured support object mappers from GSON, JAXB, Jackson, Faster Jackson and Eclipse Yasson (JSON-B).
DevQA
devqa.io โบ rest-assured-post-request
How to Submit Form Data With REST-assured Post Request
import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.Test; import static io.restassured.RestAssured.given; public class restAssuredPostRequest { @Test public void submitForm() { RestAssured.baseURI = "https://www.example.com"; given().urlEncodingEnabled(true) .param("username", "user@site.com") .param("password", "Pas54321") .header("Accept", ContentType.JSON.getAcceptHeader()) .post("/login") .then().statusCode(200); } } ... Other than submitting Form data, you can also use REST-assured POST request to send JSON payload to some resource.
Apps Developer Blog
appsdeveloperblog.com โบ home โบ java โบ restful web services โบ rest assured โบ rest assured http post request
REST Assured HTTP Post Request - Apps Developer Blog
October 27, 2022 - And finally, we can send an HTTP Post request to a RESTful Web Service endpoint. ... Below is a complete Test class source which demonstrates how to use REST Assured to test a RESTful Web Service endpoint by sending it an HTTP POST request containing JSON payload with user login credentials and then validating the Response object Headers to make sure that the required headers are present.
QA Automation Expert
qaautomation.expert โบ 2023 โบ 10 โบ 13 โบ how-to-test-post-request-using-rest-assured
How to test POST Request using Rest Assured โ QA Automation Expert
April 4, 2025 - Last Updated On HOME In the last tutorial, I explained How to test GET Request using Rest Assured. In this tutorial, I will automate a POST Request using Rest Assured. I will verify the status code, line of Status, and content of the Response. To set up a basic Rest Assured Maven Project, click ...
GitHub
github.com โบ rest-assured โบ rest-assured
GitHub - rest-assured/rest-assured: Java DSL for easy testing of REST services ยท GitHub
2025-08-15: REST Assured 5.5.6 is released with bug fixes and minor improvements. See change log for more details. ... given(). param("key1", "value1"). param("key2", "value2"). when(). post("/somewhere").
Starred by 7.1K users
Forked by 1.9K users
Languages ย Java 85.6% | Groovy 12.9%