Search code examples
springhateoasspring-hateoashal

String Hateoas link to a void method


I am working with Spring Hateoas for HAL standards in HTTP response. I have a HTTP DELETE method in my controller which returns nothing (void). And in the response for same entity I want to provide a link to delete a resource. I tried to do with following code but it gives error

Cannot resolve method linkTo(void)

    resource.add(linkTo(
            methodOn(DokumenteController.class)
                    .loeschenEinDokument(filenetDokumentZuordnung.getDokumentId()))
                            .withRel("download"));

Is there any way I can add a link to a method which returns void?


Solution

  • Don't return void. Return ResponseEntity<Void> instead.

    Chances are, that you have to set some headers anyway, even if you don't return a message body. Or you want to set a status code.

    If your controller has an appropriate request mapping you can also do the following:

     resource.add(linkTo(DokumenteController.class)
                 .slash(filenetDokumentZuordnung.getDokumentId())
                 .withRel("download"));