Spring Boot 4 Microservices & REST APIs · レッスン

初めてのRESTエンドポイントの構築

シンプルな「Hello World」RESTエンドポイントを作成し、基本的なコントローラーアノテーションを理解します。

レッスン 2/310 ステップ

「初めてのRESTエンドポイントの構築」はCoddyKit上の無料Spring Boot 4 Microservices & REST APIsレッスンです。 これはレッスン2/3です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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.

無料で開始

AI チューターと学ぶ Java — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
24
レッスン
93

よくある質問

「初めてのRESTエンドポイントの構築」レッスンは無料ですか?

はい。「初めてのRESTエンドポイントの構築」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Spring Boot 4 Microservices & REST APIsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Spring Boot 4 Microservices & REST APIsコースには全3レッスンが含まれています。

「初めてのRESTエンドポイントの構築」で何を学びますか?

シンプルな「Hello World」RESTエンドポイントを作成し、基本的なコントローラーアノテーションを理解します。 ブラウザで直接実行するハンズオンコードでSpring Boot 4 Microservices & REST APIsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Spring Boot 4 Microservices & REST APIsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのSpring Boot 4 Microservices & REST APIsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/3です。

「初めてのRESTエンドポイントの構築」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このSpring Boot 4 Microservices & REST APIsレッスンでコードを書いて実行できますか?

はい。すべてのSpring Boot 4 Microservices & REST APIsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Spring Bootプロジェクトのセットアップ
  2. 初めてのRESTエンドポイントの構築
  3. HTTPメソッドとステータスの理解
← Spring Boot 4 Microservices & REST APIsに戻る