Rest-Assured Automation Using Java

Rest-Assured Automation Using Java

Part-2

A blog for Day 2 (Part 2): Understanding REST-Assured API Requests

One of the key features of REST Assured is the ability to make API requests using a simple and intuitive syntax. In this part of the series, we will take a closer look at the various types of API requests that can be made using REST Assured.

We will look into each of the requests independently in the coming series of blogs, for the time being just understand the flow and don't worry about code snippets, we will dig deep into each and every concept so that you will be confident enough to understand any code that you encounter in this journey.

  1. GET Request: The GET request is used to retrieve information from a server. For example, the following code sends a GET request to a RESTful API and retrieves a response:

    Response response = get("https://jsonplaceholder.typicode.com/posts/1");

  2. POST Request: The POST request is used to send data to a server. For example, the following code sends a POST request to a RESTful API and includes a payload:

    Map<String, String> payload = new HashMap<>();

    payload.put("title", "foo");

    payload.put("body", "bar");

    payload.put("userId", "1");

    Response response = given() .contentType("application/json") .body(payload) .post("https://jsonplaceholder.typicode.com/posts");

  3. DELETE Request: The DELETE request is used to delete information from a server. For example, the following code sends a DELETE request to a RESTful API:

    Response response = delete("https://jsonplaceholder.typicode.com/posts/1");