What You’ll Learn:


1. Building REST APIs with Spring Boot

Example: Simple API

@RestController
@RequestMapping("/users")
public class UserController {

    @GetMapping("/{id}")
    public User getUser(@PathVariable Long id) {
        return new User(id, "John");
    }

    @PostMapping
    public User createUser(@RequestBody User user) {
        return userService.save(user);
    }
}

Annotate with @SpringBootApplication to bootstrap:

@SpringBootApplication
public class UserServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(UserServiceApplication.class, args);
    }
}

2. Service Discovery with Eureka

Used to register & discover services dynamically.

Setup:

  1. Eureka Server
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApp {
    public static void main(String[] args) {
        SpringApplication.run(DiscoveryServerApp.class, args);
    }
}

# application.properties
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

  1. Eureka Client (microservice)