# TestFly Part 6: Built-in ApiClient, BaseApiTest & Fast Hybrid UI + API Flows

URL: https://hakangul.lovable.app/blog/testfly-part-6-hybrid-web-and-api-testing-restassured
Author: Hakan Gül — Team Lead Senior Test Automation Engineer
Published: 2026-08-28
Updated: 2026-08-29
Category: api-testing
Tags: TestFly, ApiClient, ApiResponse, BaseApiTest, API Testing, JSON Schema, Java, SDET

> Execute pure API tests and hybrid UI + API workflows using TestFly's built-in ApiClient, ApiResponse assertions, and JSON Schema validation.

## English

## Native API Testing in TestFly

TestFly includes a high-performance, fluent HTTP client out of the box—no third-party dependencies required.

---

## 1. Pure API Tests with `BaseApiTest`

Extend `BaseApiTest` for API tests without launching a browser:

```java
package io.testfly.examples.api;

import io.testfly.test.BaseApiTest;
import io.testfly.client.ApiClient;
import io.testfly.client.ApiResponse;
import org.testng.annotations.Test;

public class UserApiTest extends BaseApiTest {

    @Test
    public void getUserAndValidateSchema() {
        ApiResponse res = ApiClient.get("/api/users/1")
            .header("Accept", "application/json")
            .send()
            .assertStatus(200)
            .assertJson("$.name", "Hakan Gül")
            .assertSchema("schemas/user.json");
    }
}
```

---

## 2. Hybrid UI + API Tests via `apiClient()`

In `BaseTest`, use `apiClient()` to seed data via API before opening the browser:

```java
package io.testfly.examples.tests;

import io.testfly.test.BaseTest;
import io.testfly.client.ApiResponse;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;

public class OrderCheckoutTest extends BaseTest {

    @Test
    public void fastOrderVerification() {
        // 1. Create order instantly via API (100ms)
        ApiResponse order = apiClient().post("/api/orders")
            .body(Map.of("itemId", "SKU-100", "quantity", 1))
            .send()
            .assertStatus(201);

        String orderId = order.json("$.orderId");

        // 2. Open browser directly to the order page
        open("/orders/" + orderId);
        Assert.assertEquals(getText(By.id("order-status")), "Confirmed");
    }
}
```

Every API request is automatically logged to the TestFly step timeline!

## Türkçe

## TestFly Dahili API Test Mimarisi

TestFly, harici kütüphanelere gerek duymadan çalışan yüksek performanslı ve akıcı bir HTTP istemcisi (`ApiClient`) barındırır.

---

## 1. `BaseApiTest` ile Saf API Testleri

Tarayıcı açmadan doğrudan API testleri koşmak için `BaseApiTest` sınıfını miras alın:

```java
package io.testfly.examples.api;

import io.testfly.test.BaseApiTest;
import io.testfly.client.ApiClient;
import io.testfly.client.ApiResponse;
import org.testng.annotations.Test;

public class UserApiTest extends BaseApiTest {

    @Test
    public void kullaniciGetirVeSemayiDogrula() {
        ApiResponse res = ApiClient.get("/api/users/1")
            .header("Accept", "application/json")
            .send()
            .assertStatus(200)
            .assertJson("$.name", "Hakan Gül")
            .assertSchema("schemas/user.json");
    }
}
```

---

## 2. `apiClient()` ile Hibrit UI + API Testleri

`BaseTest` içinde `apiClient()` kullanarak önce API üzerinden veriyi hazırlayın, ardından tarayıcıda doğrulayın:

```java
package io.testfly.examples.tests;

import io.testfly.test.BaseTest;
import io.testfly.client.ApiResponse;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;

public class OrderCheckoutTest extends BaseTest {

    @Test
    public void hizliSiparisDogrulama() {
        // 1. API ile 100 ms'de sipariş oluştur
        ApiResponse order = apiClient().post("/api/orders")
            .body(Map.of("itemId", "SKU-100", "quantity", 1))
            .send()
            .assertStatus(201);

        String orderId = order.json("$.orderId");

        // 2. Tarayıcıda doğrudan sipariş sayfasına git
        open("/orders/" + orderId);
        Assert.assertEquals(getText(By.id("order-status")), "Onaylandı");
    }
}
```

Tüm API istekleri TestFly HTML raporu adım çizelgesinde otomatik loglanır!
