To create a custom endpoint in Spring Boot 2.x, you can use the @Endpoint annotation. Spring Boot also exposes endpoints using @WebEndpointor, @WebEndpointExtension over HTTP with the help of Spring MVC, Jersey, etc.
xxxxxxxxxx
@Component
@Endpoint(id="custom-health")
public class CustomHealthEndPoint {
@ReadOperation
public CustomHealth health() {
Map<String, Object> details = new LinkedHashMap<>();
details.put("CustomHealthStatus", "Everything looks good");
CustomHealth health = new CustomHealth();
health.setHealthDetails(details);
return health;
}
@ReadOperation
public String customEndPointByName(@Selector String name) {
return "custom-end-point";
}
@WriteOperation
public void writeOperation(@Selector String name) {
//perform write operation
}
@DeleteOperation
public void deleteOperation(@Selector String name){
//delete operation
}
}