# TestFly Part 6: Built-in ApiClient, BaseApiTest and 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-10-18
Category: api-testing
Tags: TestFly, ApiClient, ApiResponse, BaseApiTest, API Testing, JSON Schema, Java, SDET

> Run API-only tests and hybrid UI + API tests with TestFly's built-in ApiClient, ApiResponse assertions and JSON Schema validation.

## English

## API testing in TestFly

TestFly ships with its own fluent HTTP client, so API tests need no third-party dependency.

## API-only tests with `BaseApiTest`

To test an API without launching a browser, extend `BaseApiTest`:

```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");
    }
}
```

## Hybrid UI + API tests with `apiClient()`

Inside a `BaseTest`, call `apiClient()` to seed data through the API before the browser opens. The test below creates an order with one POST request and then opens the order page directly.

```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");
    }
}
```

TestFly logs every API request to the step timeline automatically.

## Türkçe

## TestFly'da API testleri

TestFly'ın kendi HTTP istemcisi (`ApiClient`) var. Akıcı bir arayüzle çalışır ve harici bir kütüphane gerektirmez.

## `BaseApiTest` ile yalnızca API testleri

Tarayıcı açmadan API testi koşmak için test sınıfını `BaseApiTest` sınıfından türetin:

```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");
    }
}
```

## `apiClient()` ile hibrit UI + API testleri

`BaseTest` içinde `apiClient()` ile veriyi önce API üzerinden hazırlayıp ardından tarayıcıda doğrulayabilirsiniz. Aşağıdaki test siparişi tek bir POST isteğiyle oluşturuyor, sonra sipariş sayfasını doğrudan açıyor.

```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 raporundaki adım çizelgesine otomatik olarak yazılır.
