How to return status code from Java Resteasy request

Asked

Viewed 686 times

0

It’s quite intuitive to make a return of the API with an object or something like that, only you would like to make the return of 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 return of the object, but how to return the object + the status code http to inform the result of the request?

1 answer

2


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

return Response
        .status(Response.Status.OK)
        .entity(f)
        .build();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.