- Trending Categories
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
Explain DELETE request in Rest Assured.
We can execute the DELETE requests in Rest Assured. This is done with the help of the http DELETE method. It is responsible for deleting a server resource.
Delete request can have a request or response body. The status codes available for a DELETE request are listed below −
- 200 (OK)
- 204 (if there is no content for the record that we want to delete)
- 202 (Accepted, deletion is not a single operation).
We shall first send a DELETE request via Postman on an endpoint − http://dummy.restapiexample.com/api/v1/delete/100.
Using Rest Assured, we shall check if the response body contains the string Successfully! Record has been deleted.
Example
Code Implementation
import org.testng.Assert; import org.testng.annotations.Test; import io.restassured.RestAssured; import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; public class NewTest { @Test public void deleteRequest() { int record = 100; //base URI with Rest Assured class RestAssured.baseURI ="https://dummy.restapiexample.com/api/v1/"; //input details RequestSpecification r = RestAssured.given(); //request header r.header("Content-Type", "application/json"); //capture response from Delete request Response res = r.delete("/delete/"+ record); //verify status code of Response int s = res.getStatusCode(); Assert.assertEquals(s, 200); //convert response to string then validate String jsonString =res.asString(); Assert.assertEquals (jsonString.contains("Successfully! Record has been deleted"), true); } }
Output
- Related Articles
- Explain PUT request in Rest Assured.
- How to get the response time of a request in Rest Assured?
- How to validate the response time of a request in Rest Assured?
- How to pass more than one header in a request in Rest Assured?
- How to update the value of a field in a request using Rest Assured?
- How to pass the request body from an external file in a separate package in Rest Assured?
- What is Rest Assured?
- Validate JSON Schema in Rest Assured.
- What is XmlPath in Rest Assured?
- What is JSON parsing in Rest Assured?
- Explain how to get the size of a JSON array response in Rest Assured.
- How to handle static JSON in Rest Assured?
- How to validate XML response in Rest Assured?
- How to use Assertion in response in Rest Assured?
- How to use the then method in Rest Assured?

Advertisements