params() method in RestAssured

Sameera De Silva
1 min readJul 5, 2023

The params() method in RestAssured is used to specify query parameters in an HTTP request.
Query parameters are key-value pairs that are appended to the URL in the form of key=value pairs.

The params() method allows you to conveniently set multiple query parameters for your request.

The .params() method can only be used with HTTP methods that support query parameters or form data, such as GET, POST, PUT, and PATCH.

The .params() method does not support sending files. To send files, you should use the multiPart() method.

The .params() method is a synchronous method, which means that it will block until the request has been sent and the response has been received.


import static io.restassured.RestAssured.given;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

public class ParamPostExample {

@Test
public void exmaple() {

RestAssured.baseURI = "http://localhost:3000/";
RestAssured.basePath = "/posts";
int UserID = 4345;// userID is unique
String bookTitle="The haunted hill";
String authorName="Eric Kripke";


given().header("Content-Type", "application/x-www-form-urlencoded").contentType(ContentType.JSON).params("id",UserID,"title",bookTitle,"author",authorName).post("/").then().log().all();





}

}

--

--

No responses yet