0Pricing
tRPC End-to-End Type Safe APIs · درس

نظرة عامة على مفاهيم tRPC الأساسية

احصلوا على نظرة عامة رفيعة المستوى على بنية tRPC، بما في ذلك أجهزة التوجيه والإجراءات والسياق.

نظرة عامة على مفاهيم tRPC الأساسية درس مجاني في tRPC End-to-End Type Safe APIs على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في tRPC End-to-End Type Safe APIs، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة tRPC End-to-End Type Safe APIs 4 دروس في المجموع.

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

tRPC Core Concepts Intro

Time for tRPC's building blocks. We'll cover routers (how the API is organized), procedures (the functions clients call), and context (per-request data).

tRPC Flow: Client to Server

The tRPC flow: the client calls a procedure, the router routes it, the procedure runs (often using context), and a typesafe response goes back to the client.

Meet tRPC Routers

Routers are the backbone of a tRPC API. They group related procedures into modules, define your API structure, and can be merged into one full API.

Simple Router Structure

A router is just an object holding your callable functions. Here's a conceptual sketch of a minimal user router you'll fill with procedures.

import { router, publicProcedure } from '../trpc';

// This is a conceptual router definition.
// 'router' and 'publicProcedure' would be defined in your tRPC setup file.
export const userRouter = router({
  // All user-related procedures will be defined here
  // e.g., 'getUser', 'createUser', 'updateUser'
});

Understanding Procedures

Procedures are the actual functions your client calls — your API endpoints. Each defines its input, its output, and the server-side business logic.

Queries for Data Fetching

A query procedure fetches data. It should be read-only and idempotent — same input, same result — making it ideal for client-side caching. Like an HTTP GET.

Basic Query Procedure

Here's a conceptual query that fetches a user by ID: it declares an input and returns a user object.

// Inside your userRouter (from previous scene)
// This procedure gets a user by ID.
getUserById: publicProcedure
  .input(z.string()) // Expects a string (the user ID)
  .query(({ input }) => {
    // In a real app, you'd fetch from a database here.
    // For now, imagine we're returning a simple object.
    return { id: input, name: "Jane Doe", email: "jane@example.com" };
  }),

Mutations for Data Changes

A mutation changes data — create, update, delete. It has side effects and isn't idempotent, so repeated calls can differ. Like an HTTP POST, PUT, or DELETE.

tRPC Context Explained

Context is built once per request and passed to every procedure in it. It's where you stash request-scoped data like the auth user or a DB connection.

Core Concepts Check

Let's quickly check your understanding of tRPC's core building blocks.

Core Concepts Recap

Recap: routers organize the API, procedures (queries for reads, mutations for writes) do the work, and context shares per-request data. Next: your first project.

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

هل درس «نظرة عامة على مفاهيم tRPC الأساسية» مجاني؟

نعم — نص درس «نظرة عامة على مفاهيم tRPC الأساسية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة tRPC End-to-End Type Safe APIs، انتقل إلى CoddyKit PRO. تتضمن دورة tRPC End-to-End Type Safe APIs 4 دروس في المجموع.

ماذا ستتعلم في «نظرة عامة على مفاهيم tRPC الأساسية»؟

احصلوا على نظرة عامة رفيعة المستوى على بنية tRPC، بما في ذلك أجهزة التوجيه والإجراءات والسياق. تتمرن على tRPC End-to-End Type Safe APIs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ tRPC End-to-End Type Safe APIs؟

لا تُشترط خبرة سابقة. tRPC End-to-End Type Safe APIs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «نظرة عامة على مفاهيم tRPC الأساسية»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس tRPC End-to-End Type Safe APIs هذا؟

نعم. كل درس في tRPC End-to-End Type Safe APIs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

  1. ما هي tRPC؟
  2. قوة أمان الأنواع
  3. نظرة عامة على مفاهيم tRPC الأساسية
  4. إعداد أول مشروع لك باستخدام tRPC
← العودة إلى tRPC End-to-End Type Safe APIs