DEV Community

Emily Jackson
Emily Jackson

Posted on

REST Assured API Testing: Complete Beginner’s Tutorial


APIs are the invisible foundation of every modern application. Whether you’re logging into an app, making a payment, loading your Instagram feed, or booking a cab—an API is talking behind the scenes.

Because APIs play such a big role, testing them isn’t optional anymore… it’s essential.

If you’re someone who wants to learn API automation from scratch but doesn’t want to get overwhelmed, then REST Assured is one of the best places to start. It’s simple, Java-based, powerful, and widely used in real QA projects.

In this beginner-friendly guide, we’ll walk through what REST Assured is, why it’s popular, how to set it up, and how to write your first API test—even if you’ve never touched API automation before.

Let’s jump right in.

**

What Is REST Assured? (Explained Simply)

**

REST Assured is a Java library built specifically for testing RESTful APIs.
Think of it as a tool that helps you:

  • send API requests
  • validate API responses
  • automate API test cases

It works beautifully with TestNG, Maven, and CI/CD pipelines, which is why many companies use it as part of their qa automation testing services to build stable API test suites.

**

Why Do Testers Love REST Assured?

**

Because it feels like writing English.

Here’s an example:

given()
   .baseUri("https://api.example.com")
.when()
   .get("/users/1")
.then()
   .statusCode(200)
   .body("name", equalTo("John"));
Enter fullscreen mode Exit fullscreen mode

It’s readable, clean, and easy to learn compared to many other API testing tools.

**

Where REST Assured Fits in the Testing Landscape

**

Before you start building automation, it’s important to understand where REST Assured excels.

✅ Great For

  • Functional API testing
  • Validation of response status codes
  • Checking JSON/XML responses
  • Authentication testing (Bearer tokens, OAuth, etc.)
  • Integrating with TestNG, Jenkins, and CI/CD

❌ Not Meant For

  • Performance testing
  • Stress testing
  • Heavy load simulation

If you want to test how your API performs under thousands of requests, tools like JMeter are better suited. You can read more about what JMeter is used for to understand its performance-testing strengths.

This understanding helps you choose the right tool for the right job.

**

Setting Up REST Assured (Step-by-Step)

**
1. Install Java

REST Assured works with Java, so make sure JDK 8 or above is installed.

2. Install an IDE

You can use IntelliJ IDEA, Eclipse, or VS Code with Java support.

3. Create a Maven Project

Because REST Assured integrates best with Maven, create a new Maven project in your IDE.

4. Add REST Assured Dependency

Add this to your pom.xml:

<dependency>
   <groupId>io.rest-assured</groupId>
   <artifactId>rest-assured</artifactId>
   <version>5.3.0</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

If you're using TestNG:

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.10.0</version>
    <scope>test</scope>
</dependency>
Enter fullscreen mode Exit fullscreen mode

That's it.
You’re now ready to write your first API test!

**

Your First REST Assured API Test

**

Let’s test a simple GET API from “reqres.in”.

Example Test Case

import io.restassured.RestAssured;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

public class GetUserTest {

    @Test
    public void getSingleUser() {
        RestAssured.baseURI = "https://reqres.in/api";

        given()
        .when()
            .get("/users/2")
        .then()
            .statusCode(200)
            .body("data.first_name", equalTo("Janet"))
            .body("support.text", notNullValue());
    }
}
Enter fullscreen mode Exit fullscreen mode

What This Test Does

  • Calls the /users/2 API
  • Confirms the status code is 200
  • Validates the response JSON fields
  • Ensures the “support” section is not empty

This is the basic building block of all your API tests.

**

How to Add Headers, Params & Authentication

**

REST Assured makes these tasks extremely simple.

*Adding Query Parameters
*

given()
   .queryParam("page", 2)
.when()
   .get("/users")
.then()
   .statusCode(200);
Enter fullscreen mode Exit fullscreen mode

Adding Headers

given()
   .header("Content-Type", "application/json")
Enter fullscreen mode Exit fullscreen mode

Bearer Token Authentication

given()
   .auth()
   .oauth2("your_token_here")
Enter fullscreen mode Exit fullscreen mode

These features help you test real-world APIs that require sessions, roles, or security layers.

Testing POST APIs (Create a User)

Here’s how you test a POST request using REST Assured:

@Test
public void createUser() {
    String requestBody = "{ \"name\": \"Alex\", \"job\": \"Tester\" }";

    given()
        .header("Content-Type", "application/json")
        .body(requestBody)
    .when()
        .post("/users")
    .then()
        .statusCode(201)
        .body("name", equalTo("Alex"));
}

Enter fullscreen mode Exit fullscreen mode

POST, PUT, DELETE… REST Assured handles them all with the same simplicity.

**

Common REST Assured Best Practices

**

Here’s how beginners can improve their test suite quickly:

✔️ Use a Base URI

Set it once instead of repeating it everywhere.

✔️ Externalize Test Data

Keep JSON or payloads outside your code.

✔️ Reuse Request Specification

Helps keep code clean and maintainable.

✔️ Create a TestNG Suite

Group API tests for better organization.

**

Improving REST Assured Reporting

**

One limitation of REST Assured is that the default reporting from TestNG is basic.

If you're working in a team or want better insights (pass/fail trends, execution time, charts), you should adopt automated reporting tools for testing that provide rich dashboards and easy-to-share reports.

These help:

  • QA leads track stability
  • Developers debug faster
  • Teams collaborate better
  • CI pipelines show clear results

Better reporting = faster releases with fewer surprises.
**

Why REST Assured Matters in 2025 and Beyond

**

APIs keep getting more complex—microservices, cloud apps, containerized backends, and AI-driven systems rely heavily on well-tested APIs.

REST Assured remains a strong skill for QA engineers because:

  • Companies prefer code-based automation
  • CI/CD is the standard
  • API testing is growing faster than UI testing
  • It’s Java-based, making it enterprise-friendly

If you're starting your API automation journey, REST Assured is a must-learn tool.

**

Final Thoughts

**

REST Assured is simple, powerful, and perfect for beginners who want to step confidently into API automation. With easy-to-read syntax, Java compatibility, TestNG integration, and stable performance, it remains one of the most trusted tools for functional API testing.

Whether you're building a small test suite or planning enterprise-level API automation, REST Assured can handle it all.

If you’d like, I can also help you create:

✔️ A complete TestNG suite
✔️ A GitHub-ready REST Assured framework
✔️ A CI pipeline example
✔️ Or a downloadable cheatsheet

Top comments (0)