CurrentDateEndpoint

    CurrentDateEndpoint

    1. import io.micronaut.management.endpoint.annotation.Endpoint
    2. import io.micronaut.management.endpoint.annotation.Read
    3. @Endpoint(id = "date",
    4. prefix = "custom",
    5. defaultEnabled = true,
    6. defaultSensitive = false)
    7. class CurrentDateEndpoint {
    8. Date currentDate
    9. @Read
    10. Date currentDate() {
    11. }

    The above method responds to the following request:

    1. $ curl -X GET localhost:55838/date
    2. 1526085903689

    The annotation accepts an optional produces argument, which sets the media type returned from the method (default is application/json):

    CurrentDateEndpoint

    1. import io.micronaut.management.endpoint.annotation.Endpoint
    2. import io.micronaut.management.endpoint.annotation.Read
    3. import io.micronaut.http.MediaType
    4. import io.micronaut.management.endpoint.annotation.Selector
    5. prefix = "custom",
    6. defaultEnabled = true,
    7. defaultSensitive = false)
    8. class CurrentDateEndpoint {
    9. Date currentDate
    10. @Read(produces = MediaType.TEXT_PLAIN) (1)
    11. String currentDatePrefix(@Selector String prefix) {
    12. return "${prefix}: ${currentDate}"
    13. }
    14. }

    CurrentDateEndpoint

    1. $ curl -X GET localhost:8080/date/the_date_is