Class WebService

java.lang.Object
de.qytera.qtaf.http.WebService

public final class WebService extends Object
Utility class for dispatching HTTP requests.

The typical workflow for dispatching requests looks as follows:

     
  RequestBuilder request = WebService.buildRequest(new URI("https://some-url.you/need"));
  request.getBuilder()
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header(HttpHeaders.AUTHORIZATION, "my-secret");
  Response response = WebService.get(request);
  
  
  • Method Details

    • buildRequest

      public static RequestBuilder buildRequest(URI uri)
      Starting point for building HTTP requests.
      Parameters:
      uri - the URI to which the request will be sent
      Returns:
      a RequestBuilder to further modify the HTTP request
      See Also:
    • get

      public static jakarta.ws.rs.core.Response get(RequestBuilder request)
      Method for dispatching HTTP GET requests.
      Parameters:
      request - the prepared HTTP request
      Returns:
      the HTTP response
    • post

      public static jakarta.ws.rs.core.Response post(RequestBuilder request, com.google.gson.JsonElement body)
      Method for dispatching HTTP POST requests with JSON bodies. The body can be obtained using Gson's Gson.toJsonTree(Object):
       Response response = WebService.post(request, toJsonTree(data));
       
      Parameters:
      request - the prepared HTTP request
      body - the request's JSON body
      Returns:
      the HTTP response
    • put

      public static jakarta.ws.rs.core.Response put(RequestBuilder request, com.google.gson.JsonElement body)
      Method for dispatching HTTP PUT requests with JSON bodies. The body can be obtained using Gson's Gson.toJsonTree(Object):
       Response response = WebService.put(request, toJsonTree(data));
       
      Parameters:
      request - the prepared HTTP request
      body - the request's JSON body
      Returns:
      the HTTP response
    • delete

      public static jakarta.ws.rs.core.Response delete(RequestBuilder request)
      Method for dispatching HTTP DELETE requests.
      Parameters:
      request - the prepared HTTP request
      Returns:
      the HTTP response