0Pricing
Spring Boot 4 Microservices & REST APIs · Lektion

Ihren ersten REST-Endpunkt erstellen

Erstellen Sie einen einfachen „Hello World“-REST-Endpunkt und verstehen Sie die grundlegenden Controller-Annotationen.

Ihren ersten REST-Endpunkt erstellen ist eine kostenlose Spring Boot 4 Microservices & REST APIs-Lektion auf CoddyKit. Dies ist Lektion 2 von 3. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Spring Boot 4 Microservices & REST APIs-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Spring Boot 4 Microservices & REST APIs-Kurs umfasst insgesamt 3 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Ihren ersten REST-Endpunkt erstellen“ kostenlos?

Ja — der vollständige Text von „Ihren ersten REST-Endpunkt erstellen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Spring Boot 4 Microservices & REST APIs-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Spring Boot 4 Microservices & REST APIs-Kurs umfasst insgesamt 3 Lektionen.

Was lerne ich in „Ihren ersten REST-Endpunkt erstellen“?

Erstellen Sie einen einfachen „Hello World“-REST-Endpunkt und verstehen Sie die grundlegenden Controller-Annotationen. Du übst Spring Boot 4 Microservices & REST APIs mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Spring Boot 4 Microservices & REST APIs zu starten?

Keine Vorkenntnisse erforderlich. Spring Boot 4 Microservices & REST APIs auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 3.

Wie lange dauert die Lektion „Ihren ersten REST-Endpunkt erstellen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Spring Boot 4 Microservices & REST APIs-Lektion Code schreiben und ausführen?

Ja. Jede Spring Boot 4 Microservices & REST APIs-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Ihr Spring-Boot-Projekt einrichten
  2. Ihren ersten REST-Endpunkt erstellen
  3. HTTP-Methoden und Statuscodes verstehen
← Zurück zu Spring Boot 4 Microservices & REST APIs