Package com.tccc.commons.httpclient
Class JsonTemplate
java.lang.Object
com.tccc.commons.httpclient.JsonTemplate
System component that provides an easy way to issue HTTP/REST calls, such at
GET, POST, PUT, and DELETE. It is built on top of the Jetty
HttpClient
class.
The RequestContent
serializes the response to a JSON object.
Usage
public class MyClass {
@Autowired
private JsonTemplate jsonTemplate;
// . . .
}
- Since:
- 1.0
- Version:
- 2023-03-06
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T> JsonResp<T>
Performs a DELETE request on the specified URL and then parses the response into an instance of the specified class.<T> JsonResp<T>
Performs a DELETE request on the specified URI and then parses the response into an instance of the specified class.<T> JsonResp<T>
fromJson
(ContentResponse resp, Class<T> clazz, boolean envelope) Parses the body of the specified response into the specified class.<T> JsonResp<T>
Performs a GET request on the specified URL and then parses the response into an instance of the specified class.<T> JsonResp<T>
Performs a GET request on the specified URI and then parses the response into an instance of the specified class.Returns the HTTP client.<T> JsonResp<T>
Performs a POST request on the specified URL with the body object and then parses the response into an instance of the specified class.<T> JsonResp<T>
Performs a POST request on the specified URI with the body object and then parses the response into an instance of the specified class.<T> JsonResp<T>
Performs a PUT request on the specified URL with the body object and then parses the response into an instance of the specified class.<T> JsonResp<T>
Performs a PUT request on the specified URI with the body object and then parses the response into an instance of the specified class.<T> JsonResp<T>
Sends the given request and then parses the response into an instance of the specified class.<T> JsonResp<T>
send
(org.eclipse.jetty.http.HttpMethod method, String url, Object body, Class<T> clazz, boolean envelope) Sends the given request and then parses the response into an instance of the specified class.
-
Method Details
-
getClient
Returns the HTTP client.- Returns:
HttpClient
-
send
Sends the given request and then parses the response into an instance of the specified class.- Parameters:
request
- the request to sendclazz
- the response typeenvelope
- istrue
if response has kOS envelope
-
send
public <T> JsonResp<T> send(org.eclipse.jetty.http.HttpMethod method, String url, Object body, Class<T> clazz, boolean envelope) Sends the given request and then parses the response into an instance of the specified class.- Parameters:
method
- the HTTP methodurl
- the URL endpointbody
- the object which is the message bodyclazz
- the response typeenvelope
-true
if response has kOS envelope
-
GET
Performs a GET request on the specified URL and then parses the response into an instance of the specified class.- Parameters:
url
- the URL endpoint to GETclazz
- the response typeenvelope
-true
if response has kOS envelope
-
GET
Performs a GET request on the specified URI and then parses the response into an instance of the specified class.- Parameters:
uri
- the URI endpoint to GETclazz
- the response typeenvelope
-true
if response has kOS envelope
-
POST
Performs a POST request on the specified URL with the body object and then parses the response into an instance of the specified class.- Parameters:
url
- the URL endpoint to POSTbody
- the body objectclazz
- the response typeenvelope
-true
if response has kOS envelope
-
POST
Performs a POST request on the specified URI with the body object and then parses the response into an instance of the specified class.- Parameters:
uri
- the URI endpoint to POSTbody
- the body objectclazz
- the response typeenvelope
-true
if response has kOS envelope
-
PUT
Performs a PUT request on the specified URL with the body object and then parses the response into an instance of the specified class.- Parameters:
url
- the URL endpoint to PUTbody
- the body objectclazz
- the response typeenvelope
-true
if response has kOS envelope
-
PUT
Performs a PUT request on the specified URI with the body object and then parses the response into an instance of the specified class.- Parameters:
uri
- the URI endpoint to PUTbody
- the body objectclazz
- the response typeenvelope
-true
if response has kOS envelope
-
DELETE
Performs a DELETE request on the specified URL and then parses the response into an instance of the specified class.- Parameters:
url
- the URL endpoint to DELETEclazz
- the response typeenvelope
-true
if response has kOS envelope
-
DELETE
Performs a DELETE request on the specified URI and then parses the response into an instance of the specified class.- Parameters:
uri
- the URI endpoint to DELETEclazz
- the response typeenvelope
-true
if response has kOS envelope
-
fromJson
Parses the body of the specified response into the specified class.- Parameters:
resp
- the responseclazz
- the response typeenvelope
-true
if response has kOS envelope
-