CurrentDateEndpoint
CurrentDateEndpoint
import io.micronaut.management.endpoint.annotation.Endpoint
import io.micronaut.management.endpoint.annotation.Read
@Endpoint(id = "date",
prefix = "custom",
defaultEnabled = true,
defaultSensitive = false)
class CurrentDateEndpoint {
Date currentDate
@Read
Date currentDate() {
}
The above method responds to the following request:
$ curl -X GET localhost:55838/date
1526085903689
The annotation accepts an optional produces
argument, which sets the media type returned from the method (default is application/json
):
CurrentDateEndpoint
import io.micronaut.management.endpoint.annotation.Endpoint
import io.micronaut.management.endpoint.annotation.Read
import io.micronaut.http.MediaType
import io.micronaut.management.endpoint.annotation.Selector
prefix = "custom",
defaultEnabled = true,
defaultSensitive = false)
class CurrentDateEndpoint {
Date currentDate
@Read(produces = MediaType.TEXT_PLAIN) (1)
String currentDatePrefix(@Selector String prefix) {
return "${prefix}: ${currentDate}"
}
}
CurrentDateEndpoint
$ curl -X GET localhost:8080/date/the_date_is