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) Method for dispatching HTTP POST requests without bodies.static <T> jakarta.ws.rs.core.Responsepost(RequestBuilder request, jakarta.ws.rs.client.Entity<T> body) Method for dispatching HTTP POST requests with bodies.static <T> jakarta.ws.rs.core.Responseput(RequestBuilder request, jakarta.ws.rs.client.Entity<T> body) Method for dispatching HTTP PUT requests with 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 <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 likeEntity.json(Object):Response response = WebService.post(request, Entity.json(Map.of("x": 5));- Type Parameters:
T- the entity type- Parameters:
request- the prepared HTTP requestbody- the request's body- Returns:
- the HTTP response
-
post
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 likeEntity.json(Object):Response response = WebService.put(request, Entity.json(Map.of("x": 5));- Type Parameters:
T- the entity type- Parameters:
request- the prepared HTTP requestbody- the request's body- Returns:
- the HTTP response
-
delete
Method for dispatching HTTP DELETE requests.- Parameters:
request- the prepared HTTP request- Returns:
- the HTTP response
-