Real World Example

Day One on a Real Project

When you join a team at a company like Razorpay or an IT services project, your first task is usually "clone the repo and get the service running locally". The steps are the same as for ShopEase:

  1. git clone the repository.
  2. Check pom.xml for the Java version (java.version) and install that JDK.
  3. Run ./mvnw clean verify to download dependencies and run tests.
  4. Read application.yml for required settings (database URL, API keys) and set local values.
  5. Run the main class and hit /actuator/health or a simple GET endpoint.

ShopEase Health Check

package com.shopease;

import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PingController {

    @GetMapping("/ping")
    public Map<String, String> ping() {
        return Map.of("status", "UP", "service", "shopease");
    }
}

Example

curl http://localhost:8080/ping

Example output

{"status":"UP","service":"shopease"}

Practice

Exercise: Create a /version endpoint that returns {"app":"shopease","version":"0.0.1"}. Which package must the controller be in?

Show answer
package com.shopease;            // same package as ShopeaseApplication, or a sub-package

@RestController
public class VersionController {
    @GetMapping("/version")
    public Map<String, String> version() {
        return Map.of("app", "shopease", "version", "0.0.1");
    }
}