title: why is it necessary to return a Response object instead of String object to an http request in java?
body: <p>I defined my REST method to return a String data type as a response to an http request. This is it:</p>
  
  <pre><code>    @Path("/users/{name}/")
      @GET
      @Produces("application/json")
      public String getAllUserMemberships(@PathParam("name") String name) throws Exception{
  
          String doc = "{\"name\":\""+name+"\",\"message\":\"Logged in\"}";
  
          return doc;
      }
  </code></pre>
  
  <p>It works fine, But I was told by someone to rather return a <code>javax.ws.rs.core.Response</code> object as in the sample code below. This also works fine AND he says it is the best way to respond to an HTTP request But HE DOESN'T KNOW WHY.</p>
  
  <pre><code>    @Path("/users/{name}/")
      @GET
      @Produces("application/json")
      public Response getAllUserMemberships(@PathParam("name") String name) throws Exception{
  
          String doc = "{\"name\":\""+name+"\",\"message\":\"Logged in\"}";
  
  
          return Response.ok(doc, MediaType.APPLICATION_JSON).build();
      }
  </code></pre>
  
  <p><strong>MY PROBLEM IS:</strong> Is it necessary to return a Response object to an HTTP request when you can just return a String. If it is necessary, please tell me why because am in a dilemma as to which one is right for the purpose of HTTP request.
  I also fear the Response object might give me issues I may not be able to handle.</p>