Package com.symphony.bdk.http.api
Class HttpClient
java.lang.Object
com.symphony.bdk.http.api.HttpClient
Generic Restful Client built on top of the
ApiClient
.
Usage example:
final HttpClient httpClient = HttpClient.builder(() -> new ApiClientBuilder())
.basePath("https://localhost:8080")
.header("Connection", "Keep-Alive")
.header("Keep-Alive", "timeout=5, max=1000")
.cookie("foo", "bar")
.build();
final String response = httpClient.path("/api/v1/users")
.header("Authorization", "Bearer AbCdEf123456")
.get(new TypeReference<String>() {});
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd the accepted response media type.Add the request body object.static HttpClient.Builder
builder
(ApiClientBuilderProvider provider) Build anHttpClient.Builder
from anApiClientBuilderProvider
contentType
(String contentType) Add the request's Content-Type header.Add a cookie to be set.<T> T
delete
(TypeReference<T> type) Build a delete request and execute it.Add a form parameter.<T> T
get
(TypeReference<T> type) Build a get request and execute it.Add an arbitrary header.<T> T
method
(String method, TypeReference<T> type) Build a request and execute it using an arbitrary request method name.<T> T
patch
(TypeReference<T> type) Build a patch request and execute it.Set request path.<T> T
post
(TypeReference<T> type) Build a post request and execute it.<T> T
put
(TypeReference<T> type) Build a put request and execute it.queryParam
(String key, String value) Add a query parameter.
-
Method Details
-
method
Build a request and execute it using an arbitrary request method name.- Type Parameters:
T
- generic response type.- Parameters:
method
- request method name.type
- theTypeReference
object representing a generic Java type the response should convert to.- Returns:
- Response entity
- Throws:
ApiException
- if there are problems with the Api client request.
-
get
Build a get request and execute it.- Type Parameters:
T
- generic response type.- Parameters:
type
- theTypeReference
object representing a generic Java type the response should convert to.- Returns:
- Response entity.
- Throws:
ApiException
- if there are problems with the Api client request.
-
post
Build a post request and execute it.- Type Parameters:
T
- generic response type.- Parameters:
type
- theTypeReference
object representing a generic Java type the response should convert to.- Returns:
- Response entity.
- Throws:
ApiException
- if there are problems with the Api client request.
-
put
Build a put request and execute it.- Type Parameters:
T
- generic response type.- Parameters:
type
- theTypeReference
object representing a generic Java type the response should convert to.- Returns:
- Response entity.
- Throws:
ApiException
- if there are problems with the Api client request.
-
patch
Build a patch request and execute it.- Type Parameters:
T
- generic response type.- Parameters:
type
- theTypeReference
object representing a generic Java type the response should convert to.- Returns:
- Response entity.
- Throws:
ApiException
- if there are problems with the Api client request.
-
delete
Build a delete request and execute it.- Type Parameters:
T
- generic response type.- Parameters:
type
- theTypeReference
object representing a generic Java type the response should convert to.- Returns:
- Response entity.
- Throws:
ApiException
- if there are problems with the Api client request.
-
builder
Build anHttpClient.Builder
from anApiClientBuilderProvider
- Parameters:
provider
-ApiClientBuilderProvider
to instantiate theApiClientBuilder
to build aApiClient
.- Returns:
- builder to build an
ApiClient
and execute client requests.
-
path
Set request path.- Parameters:
path
- the name of the header.- Returns:
- the updated instance.
-
header
Add an arbitrary header.- Parameters:
key
- the name of the header.value
- the value of the header.- Returns:
- the updated instance.
-
cookie
Add a cookie to be set.- Parameters:
key
- the name of the cookie.value
- the value of the cookie.- Returns:
- the updated instance.
-
queryParam
Add a query parameter.- Parameters:
key
- the name of the parameter.value
- the value of the parameter.- Returns:
- the updated instance.
-
formParam
Add a form parameter.- Parameters:
key
- the name of the parameter.value
- the value of the parameter.- Returns:
- the updated instance.
-
body
Add the request body object.- Parameters:
body
- the body of the request.- Returns:
- the updated instance.
-
accept
Add the accepted response media type.- Parameters:
accept
- accepted response media type.- Returns:
- the updated instance.
-
contentType
Add the request's Content-Type header.- Parameters:
contentType
- the request's Content-Type header.- Returns:
- the updated instance.
-