Is there any way to accept multiple http mothods in Micronaut controller? For example, I would like to process GET, POST, and OPTIONS requests in a method. I tried annotated with three annotations @Get
, @Post
, and @Options
, however, only first annotation works and others are ignored.
@Controller("/echo")
public class EchoController {
private ObjectMapper mapper = new ObjectMapper();
@Get
@Post
@Options
public HttpResponse<String> process(HttpRequest<?> request) throws JsonProcessingException {
Headers headers = request.getHeaders();
return ok(mapper.writeValueAsString(headers.asMap()));
}
}
Is adding separete methods for each HTTP method and annotate them with corresponding annotation the only way to do this?
There is an open issue to allow the HTTP annotations to be repeatable.
It looks like it is planned vor 1.2.