Tworzenie pierwszego punktu końcowego REST
Utworzą Państwo prosty punkt końcowy REST „Hello World” i poznają podstawowe adnotacje kontrolerów.
Tworzenie pierwszego punktu końcowego REST to bezpłatna lekcja Spring Boot 4 Microservices & REST APIs na CoddyKit. To lekcja 2 z 3. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Spring Boot 4 Microservices & REST APIs, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Spring Boot 4 Microservices & REST APIs zawiera 3 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Często zadawane pytania
Czy lekcja „Tworzenie pierwszego punktu końcowego REST” jest bezpłatna?
Tak — pełny tekst „Tworzenie pierwszego punktu końcowego REST” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Spring Boot 4 Microservices & REST APIs, przejdź na CoddyKit PRO. Kurs Spring Boot 4 Microservices & REST APIs zawiera 3 lekcji w sumie.
Co nauczysz się w „Tworzenie pierwszego punktu końcowego REST”?
Utworzą Państwo prosty punkt końcowy REST „Hello World” i poznają podstawowe adnotacje kontrolerów. Ćwiczysz Spring Boot 4 Microservices & REST APIs z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Spring Boot 4 Microservices & REST APIs?
Nie wymagamy żadnego doświadczenia. Spring Boot 4 Microservices & REST APIs w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 3.
Ile czasu zajmuje lekcja „Tworzenie pierwszego punktu końcowego REST”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Spring Boot 4 Microservices & REST APIs?
Tak. Każda lekcja Spring Boot 4 Microservices & REST APIs zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Konfiguracja projektu Spring Boot
- Tworzenie pierwszego punktu końcowego REST
- Poznawanie metod i kodów statusu HTTP