- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to update the value of a field in a request using Rest Assured?
We can update the value of a field in a request using Rest Assured. This can be achieved with the help of the PUT request. A PUT request is used to pass data to the server for the modification of a resource. The difference between POST and PUT is that POST request is not idempotent.
This means invoking the same PUT request numerous times will always yield the same output. But invoking the same POST request numerous times will create a similar resource more than one time.
Let us send a GET request on an API and observe its response using Postman.
Using Rest Assured, we shall update the value of the title field from sunt aut facere repellat provident occaecati excepturi optio reprehenderit to Tutorialspoint.
Example
Code Implementation
import org.testng.annotations.Test; import static io.restassured.RestAssured.*; import io.restassured.RestAssured; public class NewTest { @Test void test() { //update title in body String b = "{
" +" \"title\": \"Tutorialspoint\"}"; //base URL RestAssured.baseURI = "https://jsonplaceholder.typicode.com"; //update title in body for resource id = 1 given().header("Content-type", "application/json") //adding put method .body(b).when().put("/posts/1").then().log().all() //verify status code as 200 .assertThat().statusCode(200); } }
Output
Advertisements