0

I'm learning Micronaut for our app that will be deployed to AWS Lambda. One of the endpoint needs to return a No Content. I tried different approaches but still not getting no content response.

This one returns 404 Not Found on localhost:8080

@Controller
public class MyController {

    @Get
    public HttpResponse<Void> save() {
        return HttpResponse.noContent();
    }

}

Also this one

@Controller
public class MyController {

    @Get
    @Status(HttpStatus.NO_CONTENT)
    public void save() {
        
    }
}

I tried @Post but it returns

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input

@Controller
public class MyController {

    @Post
    @Status(HttpStatus.NO_CONTENT)
    public void save() {
        
    }
}

Can anyone provide a working example. Thank you.

berty
  • 160
  • 9
  • Does `return HttpResponse.status(HttpStatus.NO_CONTENT)` work? – Jeff Scott Brown Jun 22 '21 at 13:29
  • @JeffScottBrown It has something to do with my build I guess. On the build.gradle file I changed this line `runtime("lambda")` to `runtime("netty")` and it works now. – berty Jun 23 '21 at 00:36
  • @berty Can you post that as an answer and mark it as the correct one, since that would help other people who are looking for a similar solution? – Shubhzgang Jul 07 '21 at 04:59

1 Answers1

0

It has something to do with the runtime specified on the build.gradle. I forgot to change it from runtime("lambda") to runtime("netty"), that's why testing it locally returns an error response.

berty
  • 160
  • 9