0Pricing
Edge Computing with Cloudflare Workers & Deno · Ders

Hizmet Bağlamaları ve Entegrasyonlar

Service Bindings kullanarak Workers'ı diğer Cloudflare hizmetlerine ve harici API'lere bağlayın.

Hizmet Bağlamaları ve Entegrasyonlar, CoddyKit'te ücretsiz bir Edge Computing with Cloudflare Workers & Deno 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, Edge Computing with Cloudflare Workers & Deno öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Edge Computing with Cloudflare Workers & Deno kursu toplamda 4 dersten oluşur.

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

Intro to Service Bindings

Welcome to Service Bindings! In this lesson, you'll learn how Cloudflare Workers can communicate with each other and other Cloudflare services directly.

Think of Service Bindings as secure, internal connections that unlock powerful modularity for your edge applications.

Why Use Service Bindings?

Service Bindings offer several key advantages:

  • Modularity: Break down complex Workers into smaller, reusable components.
  • Performance: Direct internal communication is faster than public HTTP requests.
  • Security: Keep internal API calls off the public internet.
  • Abstraction: Treat other Workers or services like local modules.

Worker-to-Worker Communication

One of the most common uses for Service Bindings is allowing one Worker to invoke another. This is perfect for creating microservices at the edge.

You can call a 'target' Worker from an 'invoking' Worker, passing requests and receiving responses as if they were part of the same application.

Code: The Target Worker

First, let's create a simple 'target' Worker. This Worker will respond with a specific message when called.

Save this as target-worker/src/index.js:

export default {
  async fetch(request, env, ctx) {
    return new Response("Hello from the Target Worker!", {
      status: 200,
      headers: { 'Content-Type': 'text/plain' }
    });
  },
};

Code: The Invoking Worker

Now, let's create an 'invoking' Worker that uses a binding to call our 'target' Worker. Notice how env.TARGET_WORKER.fetch(request) is used.

Save this as invoking-worker/src/index.js:

export default {
  async fetch(request, env, ctx) {
    // 'TARGET_WORKER' is the binding name defined in wrangler.toml
    const response = await env.TARGET_WORKER.fetch(request);
    const text = await response.text();
    return new Response(`Invoker received: ${text}`, {
      status: 200,
      headers: { 'Content-Type': 'text/plain' }
    });
  },
};

Configuring Worker Bindings

To connect the 'invoking' Worker to the 'target' Worker, you need to add a service_binding entry in the wrangler.toml file of your invoking Worker.

This tells Cloudflare which Worker project to connect to and what name (e.g., TARGET_WORKER) to use in your code.

# In the invoking-worker's wrangler.toml
name = "invoking-worker"
main = "src/index.js"
compatibility_date = "2023-12-01"

[[service_bindings]]
name = "TARGET_WORKER"
service = "target-worker" # Name of the target Worker project

Make sure both Workers are deployed to Cloudflare.

Bindings to Cloudflare Services

Service Bindings aren't limited to Workers! You can also bind your Worker directly to other Cloudflare services like KV Namespaces, R2 buckets, D1 databases, and Durable Objects.

This provides your Worker with direct, secure, and performant access to these resources via the env object.

Code: KV Namespace Binding

Here's how you'd configure a binding to a KV Namespace in your wrangler.toml:

# In your Worker's wrangler.toml
name = "my-worker"
main = "src/index.js"
compatibility_date = "2023-12-01"

[[kv_namespaces]]
binding = "MY_KV" # The variable name in your Worker
id = "YOUR_KV_NAMESPACE_ID" # Replace with your actual KV ID

Then, access it in your Worker's code:

export default {
  async fetch(request, env, ctx) {
    // 'MY_KV' is the binding name from wrangler.toml
    await env.MY_KV.put("greeting", "Hello from KV!");
    const message = await env.MY_KV.get("greeting");
    return new Response(`KV says: ${message}`, {
      status: 200,
      headers: { 'Content-Type': 'text/plain' }
    });
  },
};

Test Your Knowledge!

Choose the best answer.

Recap: Bindings & Integrations

You've learned about Cloudflare Worker Service Bindings!

  • They provide a powerful way for Workers to communicate with other Workers or Cloudflare services directly.
  • Benefits include modularity, performance, and security.
  • You configure bindings in your wrangler.toml file.
  • They enable complex architectures where Workers act as building blocks.

Keep exploring how these bindings can simplify your edge development!

Sıkça Sorulan Sorular

“Hizmet Bağlamaları ve Entegrasyonlar” dersi ücretsiz mi?

Evet — “Hizmet Bağlamaları ve Entegrasyonlar” 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 Edge Computing with Cloudflare Workers & Deno kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Edge Computing with Cloudflare Workers & Deno kursu toplamda 4 dersten oluşur.

“Hizmet Bağlamaları ve Entegrasyonlar” dersinde ne öğreneceğim?

Service Bindings kullanarak Workers'ı diğer Cloudflare hizmetlerine ve harici API'lere bağlayın. Edge Computing with Cloudflare Workers & Deno 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.

Edge Computing with Cloudflare Workers & Deno öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Edge Computing with Cloudflare Workers & Deno, 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.

“Hizmet Bağlamaları ve Entegrasyonlar” 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 Edge Computing with Cloudflare Workers & Deno dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Edge Computing with Cloudflare Workers & Deno 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. WebSockets ve Gerçek Zamanlılık
  2. Kuyruklar ve Eşzamansız Görevler
  3. Hizmet Bağlamaları ve Entegrasyonlar
  4. Cron Tetikleyicileri ve Zamanlanmış Worker'lar
← Edge Computing with Cloudflare Workers & Deno Sayfasına Dön