Package de.qytera.qtaf.http
Class WebService
java.lang.Object
de.qytera.qtaf.http.WebService
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 TypeMethodDescriptionstatic RequestBuilderbuildRequest(URI uri) Starting point for building HTTP requests.static jakarta.ws.rs.core.Responsedelete(RequestBuilder request) Method for dispatching HTTP DELETE requests.static jakarta.ws.rs.core.Responseget(RequestBuilder request) Method for dispatching HTTP GET requests.static jakarta.ws.rs.core.Responsepost(RequestBuilder request, com.google.gson.JsonElement body) Method for dispatching HTTP POST requests with JSON bodies.static jakarta.ws.rs.core.Responseput(RequestBuilder request, com.google.gson.JsonElement body) Method for dispatching HTTP PUT requests with JSON bodies.
-
Method Details
-
buildRequest
Starting point for building HTTP requests.- Parameters:
uri- theURIto which the request will be sent- Returns:
- a
RequestBuilderto further modify the HTTP request - See Also:
-
get
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'sGson.toJsonTree(Object):Response response = WebService.post(request, toJsonTree(data));- Parameters:
request- the prepared HTTP requestbody- 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'sGson.toJsonTree(Object):Response response = WebService.put(request, toJsonTree(data));- Parameters:
request- the prepared HTTP requestbody- the request's JSON body- Returns:
- the HTTP response
-
delete
Method for dispatching HTTP DELETE requests.- Parameters:
request- the prepared HTTP request- Returns:
- the HTTP response
-