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 Summary

    Modifier and Type
    Method
    Description
    Starting point for building HTTP requests.
    static jakarta.ws.rs.core.Response
    Method for dispatching HTTP DELETE requests.
    static jakarta.ws.rs.core.Response
    Method for dispatching HTTP GET requests.
    static jakarta.ws.rs.core.Response
    Method for dispatching HTTP POST requests without bodies.
    static <T> jakarta.ws.rs.core.Response
    post(RequestBuilder request, jakarta.ws.rs.client.Entity<T> body)
    Method for dispatching HTTP POST requests with bodies.
    static <T> jakarta.ws.rs.core.Response
    put(RequestBuilder request, jakarta.ws.rs.client.Entity<T> body)
    Method for dispatching HTTP PUT requests with bodies.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 <T> jakarta.ws.rs.core.Response post(RequestBuilder request, jakarta.ws.rs.client.Entity<T> body)
      Method for dispatching HTTP POST requests with bodies. The body can be obtained using: Entity.entity(Object, MediaType) or its utility variants like Entity.json(Object):
       Response response = WebService.post(request, Entity.json(Map.of("x": 5));
       
      Type Parameters:
      T - the entity type
      Parameters:
      request - the prepared HTTP request
      body - the request's body
      Returns:
      the HTTP response
    • post

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

      public static <T> jakarta.ws.rs.core.Response put(RequestBuilder request, jakarta.ws.rs.client.Entity<T> body)
      Method for dispatching HTTP PUT requests with bodies. The body can be obtained using: Entity.entity(Object, MediaType) or its utility variants like Entity.json(Object):
       Response response = WebService.put(request, Entity.json(Map.of("x": 5));
       
      Type Parameters:
      T - the entity type
      Parameters:
      request - the prepared HTTP request
      body - the request's 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