How to return request status code Java RestEasy

0

It is very intuitive to do a return of the API with an object or something, but would like to return an object along with the status code of the request.

@Override
@GET
@Path("/{num}/{cod}")
public Foo getFoo(@PathParam("num") long numFoo, @PathParam("cod") long codFoo) {

    Foo f = new Foo();

    try {
        f = fooDAO.buscarFoo(numFoo, codFoo);
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return f;
}

This way I have the object return, but how do I return the object + status code http to inform the result of the request?

    
asked by anonymous 21.02.2017 / 13:47

1 answer

1

You can return javax.ws.rs.core.Response in your method:

return Response
        .status(Response.Status.OK)
        .entity(f)
        .build();
    
21.02.2017 / 14:03