Building Your First REST Endpoint
Create a simple 'Hello World' REST endpoint and understand basic controller annotations.
Building Your First REST Endpoint is a free Spring Boot 4 Microservices & REST APIs lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Spring Boot 4 Microservices & REST APIs learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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.
Frequently asked questions
Is the “Building Your First REST Endpoint” lesson free?
Yes — the full text of “Building Your First REST Endpoint” is free to read here on the web, and the Spring Boot 4 Microservices & REST APIs course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Spring Boot 4 Microservices & REST APIs course, upgrade to CoddyKit PRO.
What will I learn in “Building Your First REST Endpoint”?
Create a simple 'Hello World' REST endpoint and understand basic controller annotations. You practise Spring Boot 4 Microservices & REST APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Spring Boot 4 Microservices & REST APIs?
No prior experience is required. Spring Boot 4 Microservices & REST APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Building Your First REST Endpoint” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Spring Boot 4 Microservices & REST APIs lesson?
Yes. Every Spring Boot 4 Microservices & REST APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Setting Up Your Spring Boot Project
- Building Your First REST Endpoint
- Understanding HTTP Methods & Statuses