Home > Net >  There's a alternative for ResponseEntity in Quarkus?
There's a alternative for ResponseEntity in Quarkus?

Time:12-02

there's a way to code a ResponseEntity like this return ResponseEntity.badRequest().body("The input vote is not valid"), in quarkus? I'm seaching for something like this, but I only found the RestResponse and didn't have the implementation that I need.

I've tried `

RestResponse.notFound()

But is not like the Spring ResponseEntity

CodePudding user response:

If you are using RESTEasy, then use a ResponseBuilder.

Code from docs

package org.acme.rest;

import java.time.Duration; 
import java.time.Instant; 
import java.util.Date;

import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.core.MediaType; 
import javax.ws.rs.core.NewCookie;

import org.jboss.resteasy.reactive.RestResponse; 
import org.jboss.resteasy.reactive.RestResponse.ResponseBuilder;

@Path("") 
public class Endpoint {

    @GET
    public RestResponse<String> hello() {
        // HTTP OK status with text/plain content type
        return ResponseBuilder.ok("Hello, World!", MediaType.TEXT_PLAIN_TYPE)
         // set a response header
         .header("X-Cheese", "Camembert")
         // set the Expires response header to two days from now
         .expires(Date.from(Instant.now().plus(Duration.ofDays(2))))
         // send a new cookie
         .cookie(new NewCookie("Flavour", "chocolate"))
         // end of builder API
         .build();
    } 
} 
  • Related