Creación de su primer endpoint REST
Cree un endpoint REST sencillo de «Hello World» y comprenda las anotaciones básicas de los controladores.
Creación de su primer endpoint REST es una lección gratuita de Spring Boot 4 Microservices & REST APIs en CoddyKit. Esta es la lección 2 de 3. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Spring Boot 4 Microservices & REST APIs, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Spring Boot 4 Microservices & REST APIs incluye 3 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Creación de su primer endpoint REST» es gratis?
Sí — el texto completo de «Creación de su primer endpoint REST» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Spring Boot 4 Microservices & REST APIs, actualiza a CoddyKit PRO. El curso de Spring Boot 4 Microservices & REST APIs incluye 3 lecciones en total.
¿Qué aprenderé en «Creación de su primer endpoint REST»?
Cree un endpoint REST sencillo de «Hello World» y comprenda las anotaciones básicas de los controladores. Practicas Spring Boot 4 Microservices & REST APIs con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Spring Boot 4 Microservices & REST APIs?
No se requiere experiencia previa. Spring Boot 4 Microservices & REST APIs en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 3.
¿Cuánto tiempo toma la lección «Creación de su primer endpoint REST»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Spring Boot 4 Microservices & REST APIs?
Sí. Cada lección de Spring Boot 4 Microservices & REST APIs incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Configuración de su proyecto Spring Boot
- Creación de su primer endpoint REST
- Comprensión de los métodos y estados HTTP