0Pricing
Spring Boot 4 Microservices & REST APIs · درس

إنشاء أول نقطة نهاية REST

أنشئ نقطة نهاية REST بسيطة تعرض 'Hello World' وافهم التعليقات التوضيحية الأساسية لوحدات التحكم.

إنشاء أول نقطة نهاية REST درس مجاني في Spring Boot 4 Microservices & REST APIs على CoddyKit. هذا هو الدرس 2 من أصل 3. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Spring Boot 4 Microservices & REST APIs، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Spring Boot 4 Microservices & REST APIs 3 دروس في المجموع.

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

What's a REST Endpoint?

An endpoint is a specific URL where your app can be reached — a unique doorbell for one function. Our goal: build one that says “Hello!”

Spring Boot Makes REST Easy

Spring Boot is great for REST APIs: minimal setup, an embedded server like Tomcat, and convention over configuration — less boilerplate, more building.

Meet @RestController

@RestController marks a class to handle web requests and return data directly. It bundles @Controller with @ResponseBody — the core REST building block.

Code Your First Endpoint

Let’s code a Hello CoddyKit! endpoint at the root path /. Run it to see your first Spring Boot API respond.

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class FirstApiApplication {

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

    @GetMapping("/")
    public String hello() {
        return "Hello CoddyKit!";
    }
}

Decoding @GetMapping

@GetMapping("/") maps HTTP GET requests to a method, and the path in parentheses sets the URL. So a GET to / calls hello().

Running Your Application

On run, Spring Boot starts an embedded Tomcat on port 8080, scans for annotations like @RestController and @GetMapping, and registers your endpoints.

Test Your Endpoint!

Now test it: open http://localhost:8080/ in a browser (or curl it) and you’ll see “Hello CoddyKit!” — your first live endpoint.

Mapping Specific Paths

Want more endpoints? Just give each @GetMapping a different path. Here we add a second one at /greet.

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class FirstApiApplication {

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

    @GetMapping("/")
    public String hello() {
        return "Hello CoddyKit!";
    }

    @GetMapping("/greet")
    public String greet() {
        return "Greetings from Spring Boot!";
    }
}

Quick Check: Endpoint Basics

Which annotation tells Spring Boot that a class is a web controller and its methods should return data directly as the response body?

Recap: Your First API

Nice work! You built your first REST API — what an endpoint is, the @RestController annotation, @GetMapping for paths, and running and hitting your app.

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

هل درس «إنشاء أول نقطة نهاية REST» مجاني؟

نعم — نص درس «إنشاء أول نقطة نهاية REST» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Spring Boot 4 Microservices & REST APIs، انتقل إلى CoddyKit PRO. تتضمن دورة Spring Boot 4 Microservices & REST APIs 3 دروس في المجموع.

ماذا ستتعلم في «إنشاء أول نقطة نهاية REST»؟

أنشئ نقطة نهاية REST بسيطة تعرض 'Hello World' وافهم التعليقات التوضيحية الأساسية لوحدات التحكم. تتمرن على Spring Boot 4 Microservices & REST APIs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Spring Boot 4 Microservices & REST APIs؟

لا تُشترط خبرة سابقة. Spring Boot 4 Microservices & REST APIs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 3.

كم من الوقت يستغرق درس «إنشاء أول نقطة نهاية REST»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس Spring Boot 4 Microservices & REST APIs هذا؟

نعم. كل درس في Spring Boot 4 Microservices & REST APIs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

  1. إعداد مشروع Spring Boot
  2. إنشاء أول نقطة نهاية REST
  3. فهم أساليب HTTP ورموزه
← العودة إلى Spring Boot 4 Microservices & REST APIs