0Pricing
Supabase Backend as a Service · درس

مقدمة إلى Edge Functions

افهموا مفهوم الوظائف عديمة الخوادم، وكيف تعزّز Supabase Edge Functions المبنية على Deno إمكانات الواجهة الخلفية لديكم.

مقدمة إلى Edge Functions درس مجاني في Supabase Backend as a Service على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Supabase Backend as a Service، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Supabase Backend as a Service 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Say Hello to Serverless!

Welcome to Supabase Edge Functions! Before we dive in, let's understand serverless functions. Traditionally, you'd manage servers to run your backend code.

With serverless, you write code, and a cloud provider handles all the server management for you. You just focus on your logic!

Why Go Serverless?

Serverless functions offer some powerful advantages:

  • Automatic Scaling: They scale up or down instantly with demand.
  • Pay-per-use: You only pay for the compute time your functions actually run.
  • Reduced Ops: No servers to provision, patch, or maintain.
  • Faster Development: Focus purely on writing your application logic.

Supabase's Serverless Power

Supabase offers its own brand of serverless functions called Edge Functions. They extend your Supabase project's capabilities without needing to set up a separate server.

Think of them as tiny pieces of backend logic that run on demand, close to your users.

Powered by Deno

Supabase Edge Functions are built on Deno, a secure runtime for JavaScript and TypeScript. Deno is a modern alternative to Node.js.

This means you can write your functions in TypeScript right out of the box, enjoying type safety and modern JavaScript features without complex setup.

How Edge Functions Work

Edge Functions are event-driven. They only execute when triggered by an event, like an HTTP request from your application or a webhook.

They are also stateless, meaning each execution is independent. This design helps them scale efficiently.

What Can They Do?

Edge Functions are incredibly versatile! Here are some common use cases:

  • Custom API Endpoints: Build your own API routes.
  • Webhook Handlers: Process events from other services.
  • Data Transformations: Modify data before or after database operations.
  • Backend Logic: Run complex calculations or integrate with external APIs.

A Simple 'Hello' Function

Let's look at a basic Edge Function. This Deno code defines a function that responds to an HTTP request, expecting a name in its body.

Try running it to see the simple JSON response!

Deno.serve(async (req) => {
  const { name } = await req.json();

  return new Response(
    JSON.stringify({ message: `Hello, ${name || 'World'}!` }),
    {
      headers: { 'Content-Type': 'application/json' },
      status: 200,
    },
  );
});

The Power of the 'Edge'

The 'Edge' in Edge Functions means they run geographically close to your users. This significantly reduces latency, making your applications feel faster and more responsive.

Supabase handles deploying your functions to a global network of servers for optimal performance.

Invoking Your Function

Once deployed, you can easily call your Edge Functions from your client-side application using the Supabase client library. Here's a JavaScript example for our 'hello-world' function:

import { createClient } from '@supabase/supabase-js';

// Replace with your actual Supabase project URL and Anon Key
const supabaseUrl = 'https://your-project-ref.supabase.co';
const supabaseAnonKey = 'YOUR_ANON_KEY';

const supabase = createClient(supabaseUrl, supabaseAnonKey);

async function callHelloFunction() {
  const { data, error } = await supabase.functions.invoke('hello-world', {
    body: { name: 'CoddyKit User' },
  });

  if (error) {
    console.error('Error invoking function:', error);
  } else {
    console.log('Function response:', data);
  }
}

callHelloFunction();

Edge Function Essentials

Let's check your understanding of Supabase Edge Functions!

Recap: Edge Functions Intro

Great job! You've learned the basics of serverless computing and Supabase Edge Functions.

  • Edge Functions are Supabase's serverless offering.
  • They run on the Deno runtime, supporting TypeScript.
  • They offer automatic scaling, pay-per-use, and reduced ops.
  • They execute on demand, close to your users.

Next, we'll learn how to deploy your first function!

الأسئلة الشائعة

هل درس «مقدمة إلى Edge Functions» مجاني؟

نعم — نص درس «مقدمة إلى Edge Functions» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Supabase Backend as a Service، انتقل إلى CoddyKit PRO. تتضمن دورة Supabase Backend as a Service 4 دروس في المجموع.

ماذا ستتعلم في «مقدمة إلى Edge Functions»؟

افهموا مفهوم الوظائف عديمة الخوادم، وكيف تعزّز Supabase Edge Functions المبنية على Deno إمكانات الواجهة الخلفية لديكم. تتمرن على Supabase Backend as a Service مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Supabase Backend as a Service؟

لا تُشترط خبرة سابقة. Supabase Backend as a Service على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «مقدمة إلى Edge Functions»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Supabase Backend as a Service هذا؟

نعم. كل درس في Supabase Backend as a Service يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. مقدمة إلى Edge Functions
  2. نشر وظيفتكم الأولى
  3. دمج الوظائف مع تطبيقكم
  4. الأسرار ومتغيرات البيئة والوظائف المجدولة
← العودة إلى Supabase Backend as a Service