0Pricing
Spring Boot 4 Microservices & REST APIs · Ders

Tepkisel Çağrılar için WebClient

Diğer hizmetleri tepkisel biçimde çağırın.

Tepkisel Çağrılar için WebClient, CoddyKit'te ücretsiz bir Spring Boot 4 Microservices & REST APIs dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Spring Boot 4 Microservices & REST APIs öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What is WebClient

WebClient is the non-blocking, reactive HTTP client in Spring WebFlux. It replaces the blocking RestTemplate for reactive apps.

  • Returns Mono / Flux responses
  • Fully non-blocking on the Netty event loop

Building a WebClient

Create an instance with a base URL using the builder.

WebClient client = WebClient.builder()
    .baseUrl("https://api.example.com")
    .build();

A Simple GET

Chain get(), uri(), retrieve(), then convert the body to a publisher.

Mono<User> user = client.get()
    .uri("/users/{id}", 1)
    .retrieve()
    .bodyToMono(User.class);
user.subscribe(System.out::println);

Fetching a Collection

Use bodyToFlux when the response is a JSON array.

Flux<User> users = client.get()
    .uri("/users")
    .retrieve()
    .bodyToFlux(User.class);

Sending a POST Body

Use post() and bodyValue() to send a request body.

Mono<User> created = client.post()
    .uri("/users")
    .bodyValue(new User("Alice"))
    .retrieve()
    .bodyToMono(User.class);

Adding Headers

Attach headers per request or globally on the builder.

Mono<String> result = client.get()
    .uri("/data")
    .header("Authorization", "Bearer token123")
    .retrieve()
    .bodyToMono(String.class);

Handling Error Statuses

retrieve() throws on 4xx/5xx by default. Customize with onStatus.

Mono<User> user = client.get()
    .uri("/users/{id}", 99)
    .retrieve()
    .onStatus(HttpStatusCode::is4xxClientError,
        resp -> Mono.error(new RuntimeException("Not found")))
    .bodyToMono(User.class);

Composing Calls with flatMap

Because results are reactive, you can chain dependent HTTP calls without blocking.

Mono<Order> order = client.get()
    .uri("/users/{id}", 1)
    .retrieve()
    .bodyToMono(User.class)
    .flatMap(u -> client.get()
        .uri("/orders?userId={id}", u.getId())
        .retrieve()
        .bodyToMono(Order.class));

Timeouts

Apply a timeout with the timeout operator so slow upstreams fail fast.

Mono<User> user = client.get()
    .uri("/users/1")
    .retrieve()
    .bodyToMono(User.class)
    .timeout(Duration.ofSeconds(3));

Retrying on Failure

Use the retry operator to re-subscribe on error a fixed number of times.

Mono<User> user = client.get()
    .uri("/users/1")
    .retrieve()
    .bodyToMono(User.class)
    .retry(2);

Registering as a Bean

Configure a shared WebClient bean so it can be injected anywhere.

@Bean
public WebClient webClient() {
    return WebClient.builder()
        .baseUrl("https://api.example.com")
        .build();
}

Quick Check

Test your understanding of WebClient.

Recap

You learned to make non-blocking HTTP calls with WebClient:

  • Build with WebClient.builder().baseUrl(...)
  • retrieve().bodyToMono/bodyToFlux for responses
  • onStatus for error handling
  • timeout and retry for resilience

Sıkça Sorulan Sorular

“Tepkisel Çağrılar için WebClient” dersi ücretsiz mi?

Evet — “Tepkisel Çağrılar için WebClient” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Spring Boot 4 Microservices & REST APIs kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.

“Tepkisel Çağrılar için WebClient” dersinde ne öğreneceğim?

Diğer hizmetleri tepkisel biçimde çağırın. Spring Boot 4 Microservices & REST APIs ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Spring Boot 4 Microservices & REST APIs öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Spring Boot 4 Microservices & REST APIs, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“Tepkisel Çağrılar için WebClient” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Spring Boot 4 Microservices & REST APIs dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Spring Boot 4 Microservices & REST APIs dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Mono ve Flux Temelleri
  2. Tepkisel Controller'lar
  3. Tepkisel Çağrılar için WebClient
  4. Geri Basınç ve Operatörler
← Spring Boot 4 Microservices & REST APIs Sayfasına Dön