0Pricing
Spring Boot 4 Microservices & REST APIs · Leçon

Créer votre premier point de terminaison REST

Créez un point de terminaison REST simple de type « Hello World » et comprenez les annotations de base des contrôleurs.

Créer votre premier point de terminaison REST est une leçon Spring Boot 4 Microservices & REST APIs gratuite sur CoddyKit. Ceci est la leçon 2 sur 3. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Spring Boot 4 Microservices & REST APIs, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Spring Boot 4 Microservices & REST APIs comprend 3 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

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.

Questions Fréquemment Posées

La leçon « Créer votre premier point de terminaison REST » est-elle gratuite ?

Oui — le texte complet de « Créer votre premier point de terminaison REST » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Spring Boot 4 Microservices & REST APIs, passe à CoddyKit PRO. Le cours Spring Boot 4 Microservices & REST APIs comprend 3 leçons au total.

Qu'est-ce que j'apprendrai dans « Créer votre premier point de terminaison REST » ?

Créez un point de terminaison REST simple de type « Hello World » et comprenez les annotations de base des contrôleurs. Tu pratiques Spring Boot 4 Microservices & REST APIs avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Spring Boot 4 Microservices & REST APIs ?

Aucune expérience préalable n'est requise. Spring Boot 4 Microservices & REST APIs sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 3.

Combien de temps prend la leçon « Créer votre premier point de terminaison REST » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Spring Boot 4 Microservices & REST APIs ?

Oui. Chaque leçon Spring Boot 4 Microservices & REST APIs inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Configurer votre projet Spring Boot
  2. Créer votre premier point de terminaison REST
  3. Comprendre les méthodes et les codes d’état HTTP
← Retour à Spring Boot 4 Microservices & REST APIs