Search code examples
restannotationsmicronaut

Micronaut Delete Annotation not creating endpoint


I have the following controller using @Endpoint

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.micronaut.http.annotation.Body
import io.micronaut.http.annotation.Delete
import io.micronaut.management.endpoint.annotation.Endpoint
import io.micronaut.management.endpoint.annotation.Read
import io.micronaut.management.endpoint.annotation.Selector
import istc.g2g.refund.dao.RefundRepository
import istc.g2g.refund.domain.Refund

import javax.inject.Inject
import javax.inject.Singleton

@Slf4j
@Endpoint(id = "refund", defaultSensitive = false)
@Singleton
@CompileStatic
class RefundController {

    @Inject
    RefundRepository refundRepository

    @Read
    Refund get(@Selector Long tin) {
        refundRepository.findByTin(tin).orElse(null)
    }

    @Delete
    void delete (@Body String foo) {
        log.debug("Deleting")
    }
}

Read and Write endpoints show up find. But Delete aren't as shown by the routes endpoint:

{
    "{[/refund/{tin}],method=[GET],produces=[application/json]}": {
        "method": "istc.g2g.refund.domain.Refund istc.g2g.refund.controller.RefundController.get(java.lang.Long tin)"
    },
    "{[/routes],method=[GET],produces=[application/json]}": {
        "method": "io.reactivex.Single io.micronaut.management.endpoint.routes.RoutesEndpoint.getRoutes()"
    },
    "{[/refresh],method=[POST],produces=[application/json]}": {
        "method": "[Ljava.lang.String; io.micronaut.management.endpoint.refresh.RefreshEndpoint.refresh(java.lang.Boolean force)"
    }
}

A request to the endpoint like in the docs just shows not found:

$ curl -X DELETE http://localhost:8083/refund
{
  "_links" : {
    "self" : {
      "href" : "/refund",
      "templated" : false
    }
  },
  "message" : "Page Not Found"
}

I can't find any evidence that any additional configuration should be needed for @Delete.

Note that if I change the annotation to @Read and use a GET request, then it works find.

Any ideas?


Solution

  • You are using the wrong Delete annotation.

    import io.micronaut.http.annotation.Delete -> import io.micronaut.management.endpoint.annotation.Delete

    EDIT: Also that @Body annotation isn't doing anything in this context.