Skip to content

Instantly share code, notes, and snippets.

@rayyildiz
Last active August 5, 2025 16:48
Show Gist options
  • Select an option

  • Save rayyildiz/50104b8c17da585b948aa2ca0a24178c to your computer and use it in GitHub Desktop.

Select an option

Save rayyildiz/50104b8c17da585b948aa2ca0a24178c to your computer and use it in GitHub Desktop.
//usr/bin/env jbang "$0" "$@" ; exit $?
// JAVA 21
// DEPS org.springframework.boot:spring-boot-dependencies:4.0.0-M1@pom
// DEPS org.springframework.boot:spring-boot-starter-web
// DEPS org.springframework.boot:spring-boot-starter-actuator
//
// JAVA_OPTIONS -Dserver.port=8080
// JAVA_OPTIONS -Dmanagement.endpoints.web.exposure.include=health,env,loggers
// REPOS mavencentral
package dev.ayyildiz;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
record Time(String currentTime, long epoch) {}
@RestController
@RequestMapping("/api")
class ApiController {
@GetMapping("/time")
public Time getTime() {
var currentTime = LocalDateTime.now().toString();
var epoch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
return new Time(currentTime, epoch);
}
}
@RestController
class HealthController {
@GetMapping("/health")
public String getHealth() {
return "Healthy";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment