CurrentDateEndpoint

    CurrentDateEndpoint

    1. import io.micronaut.management.endpoint.annotation.Endpoint
    2. import io.micronaut.management.endpoint.annotation.Write
    3. import io.micronaut.http.MediaType
    4. import io.micronaut.management.endpoint.annotation.Selector
    5. @Endpoint(id = "date",
    6. prefix = "custom",
    7. defaultEnabled = true,
    8. defaultSensitive = false)
    9. class CurrentDateEndpoint {
    10. Date currentDate
    11. String reset() {
    12. currentDate = new Date()
    13. return "Current date reset"
    14. }
    15. }

    The above method responds to the following request:

    1. $ curl -X POST http://localhost:39357/date
    2. Current date reset

    The annotation accepts an optional consumes argument, which sets the media type accepted by the method (default is application/json):

    MessageEndpoint

    1. import io.micronaut.management.endpoint.annotation.Endpoint
    2. import io.micronaut.management.endpoint.annotation.Write
    3. @Endpoint(id = "message", defaultSensitive = false)
    4. class MessageEndpoint {
    5. String message
    6. @Write(consumes = MediaType.APPLICATION_FORM_URLENCODED, produces = MediaType.TEXT_PLAIN)
    7. String updateMessage(String newMessage) { (1)
    8. message = newMessage
    9. return "Message updated"
    10. }
    11. }

    MessageEndpoint

    1. $ curl -X POST http://localhost:65013/message -H 'Content-Type: application/x-www-form-urlencoded' -d $'newMessage=A new message'