Search in sources :

Example 1 with Produces

use of io.micronaut.http.annotation.Produces in project micronaut-starter by micronaut-projects.

the class ApplicationController method home.

/**
 * Provides a description of the API.
 * @param request The request
 * @return A description of the API.
 */
@Get("/")
@Produces(MediaType.TEXT_PLAIN)
@ApiResponse(responseCode = "200", description = "A textual description of the API", content = @Content(mediaType = MediaType.TEXT_PLAIN))
HttpResponse<Writable> home(HttpRequest<?> request, @Parameter(hidden = true) RequestInfo info) {
    Collection<MediaType> accept = request.accept();
    URI redirectURI = configuration.getRedirectUri().orElse(null);
    if (accept.contains(MediaType.TEXT_HTML_TYPE) && redirectURI != null) {
        return HttpResponse.permanentRedirect(redirectURI);
    } else {
        return HttpResponse.ok(new Writable() {

            @Override
            public void writeTo(Writer out) {
            // no-op
            }

            @Override
            public void writeTo(OutputStream outputStream, @Nullable Charset charset) {
                new RockerWritable(new starterApi().serverURL(info.getServerURL()).micronautVersion(VersionInfo.getMicronautVersion())).write(outputStream);
            }
        });
    }
}
Also used : RockerWritable(io.micronaut.starter.template.RockerWritable) io.micronaut.starter.template.api.starterApi(io.micronaut.starter.template.api.starterApi) OutputStream(java.io.OutputStream) MediaType(io.micronaut.http.MediaType) RockerWritable(io.micronaut.starter.template.RockerWritable) Writable(io.micronaut.core.io.Writable) Charset(java.nio.charset.Charset) URI(java.net.URI) Writer(java.io.Writer) Produces(io.micronaut.http.annotation.Produces) Get(io.micronaut.http.annotation.Get) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Aggregations

Writable (io.micronaut.core.io.Writable)1 MediaType (io.micronaut.http.MediaType)1 Get (io.micronaut.http.annotation.Get)1 Produces (io.micronaut.http.annotation.Produces)1 RockerWritable (io.micronaut.starter.template.RockerWritable)1 io.micronaut.starter.template.api.starterApi (io.micronaut.starter.template.api.starterApi)1 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 OutputStream (java.io.OutputStream)1 Writer (java.io.Writer)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1