0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · درس

إعداد مشروع بوابة أساسي

هيّئوا مشروع Spring Boot باستخدام Spring Cloud Gateway واضبطوا بوابة بسيطة عاملة.

إعداد مشروع بوابة أساسي درس مجاني في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.

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

Gateway Project Setup

Welcome! In this lesson, you'll learn how to initialize a basic Spring Cloud Gateway project. This is your first step to building powerful API gateways.

We'll cover setting up the necessary dependencies and creating a minimal working gateway configuration.

What You'll Need

Before we dive in, ensure you have the following tools installed:

  • Java Development Kit (JDK) 17+: For running Spring Boot applications.
  • Maven or Gradle: Build automation tools for managing project dependencies.
  • An IDE (e.g., IntelliJ IDEA, VS Code): For writing and managing your code.

These are standard for Spring Boot development.

Start with Spring Initializr

The easiest way to start any Spring Boot project is with Spring Initializr. It helps you generate a project with all the necessary setup.

For our gateway, you'll select specific dependencies to get started quickly.

Key Gateway Dependencies

When using Spring Initializr, search for and add these key dependencies:

  • Spring Cloud Gateway: This is the core library that provides gateway functionality.
  • Spring WebFlux: Gateway is built on reactive programming, so WebFlux is a transitive dependency and crucial for its operation.

Choose your preferred build tool (Maven or Gradle) and Java version (e.g., 17 or 21).

The Main Application Class

After generating and importing your project, you'll find a main application class. This class uses @SpringBootApplication to bootstrap your application.

Run this simple Spring Boot application to see it start up. It won't do much yet, but it's alive!

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class GatewayProjectApplication {

  public static void main(String[] args) {
    SpringApplication.run(GatewayProjectApplication.class, args);
  }
}

Configuring Gateway Routes

Now that our application can run, we need to tell the gateway what to do! This is done by defining routes in your application.yml (or application.properties) file.

A route maps incoming requests to a specific backend service based on certain conditions.

Basic Route Example

Let's add a simple route to src/main/resources/application.yml. This route will forward requests from /get to http://httpbin.org:80, a public testing service.

This is your first step to proxying requests!

spring:
  cloud:
    gateway:
      routes:
        - id: httpbin_route
          uri: http://httpbin.org:80
          predicates:
            - Path=/get

Understanding the Route

Let's break down that route configuration:

  • id: httpbin_route: A unique identifier for this route.
  • uri: http://httpbin.org:80: The target backend service URL where requests will be forwarded.
  • predicates: - Path=/get: A condition that must be met for this route to activate. Here, it means any request with a path starting with /get.

Predicates are like 'if' statements for routing.

Running & Testing Your Gateway

With the application.yml updated, restart your Spring Boot application. The gateway will now pick up the new route.

You can test it using curl or your web browser:

  • Open your terminal.
  • Run: curl http://localhost:8080/get

You should see a JSON response from httpbin.org, proving your gateway is working!

Gateway Setup Check

You've just set up your first Spring Cloud Gateway project!

Which of the following is the primary dependency required to enable Spring Cloud Gateway functionality in a Spring Boot project?

Recap: Basic Gateway Setup

Great job! You've learned how to:

  • Initialize a Spring Boot project using Spring Initializr.
  • Add the essential spring-cloud-starter-gateway dependency.
  • Create a basic Spring Cloud Gateway application class.
  • Configure your first gateway route in application.yml.
  • Test your gateway to ensure it's forwarding requests correctly.

This foundational knowledge will help you build more complex gateway configurations in future lessons!

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

هل درس «إعداد مشروع بوابة أساسي» مجاني؟

نعم — نص درس «إعداد مشروع بوابة أساسي» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، انتقل إلى CoddyKit PRO. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.

ماذا ستتعلم في «إعداد مشروع بوابة أساسي»؟

هيّئوا مشروع Spring Boot باستخدام Spring Cloud Gateway واضبطوا بوابة بسيطة عاملة. تتمرن على API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)؟

لا تُشترط خبرة سابقة. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «إعداد مشروع بوابة أساسي»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) هذا؟

نعم. كل درس في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

  1. البوابة مقابل الخدمات المصغّرة التقليدية
  2. إعداد مشروع بوابة أساسي
  3. تعريف المسارات والاختبارات الشرطية
  4. فهم الأساس التفاعلي
← العودة إلى API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)