Class ApiClient
- java.lang.Object
-
- dev.openfga.sdk.api.client.ApiClient
-
public class ApiClient extends java.lang.ObjectConfiguration and utility class for API clients.This class can be constructed and modified, then used to instantiate the various API classes. The API classes use the settings in this class to configure themselves, but otherwise do not store a link to this class.
This class is mutable and not synchronized, so it is not thread-safe. The API classes generated from this are immutable and thread-safe.
The setter methods of this class return the current object to facilitate a fluent style of configuration.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRequestInterceptor(java.util.function.Consumer<java.net.http.HttpRequest.Builder> interceptor)Add a custom request interceptor.protected java.net.http.HttpClient.BuildercreateDefaultHttpClientBuilder()protected com.fasterxml.jackson.databind.ObjectMappercreateDefaultObjectMapper()static java.net.http.HttpRequest.BuilderformRequestBuilder(java.lang.String method, java.lang.String path, java.lang.String body, Configuration configuration)Creates aHttpRequest.Builderfor ax-www-form-urlencodedrequest.java.util.function.Consumer<java.net.http.HttpResponse<java.lang.String>>getAsyncResponseInterceptor()Get the custom async response interceptor.protected java.lang.StringgetDefaultBaseUri()java.net.http.HttpClientgetHttpClient()Get anHttpClientbased on the currentHttpClient.Builder.java.net.http.HttpClient.BuildergetHttpClientBuilder()Get the currentHttpClient.Builder.com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()Get a copy of the currentObjectMapper.java.util.function.Consumer<java.net.http.HttpRequest.Builder>getRequestInterceptor()Get the custom interceptor.java.util.function.Consumer<java.net.http.HttpResponse<java.io.InputStream>>getResponseInterceptor()Get the custom response interceptor.static java.net.http.HttpRequest.BuilderrequestBuilder(java.lang.String method, java.lang.String path, byte[] body, Configuration configuration)static java.net.http.HttpRequest.BuilderrequestBuilder(java.lang.String method, java.lang.String path, Configuration configuration)ApiClientsetAsyncResponseInterceptor(java.util.function.Consumer<java.net.http.HttpResponse<java.lang.String>> interceptor)Set a custom async response interceptor.ApiClientsetHttpClientBuilder(java.net.http.HttpClient.Builder builder)Set a customHttpClient.Builderobject to use when creating theHttpClientthat is used by the API client.ApiClientsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)Set a customObjectMapperto serialize and deserialize the request and response bodies.ApiClientsetRequestInterceptor(java.util.function.Consumer<java.net.http.HttpRequest.Builder> interceptor)Set a custom request interceptor.ApiClientsetResponseInterceptor(java.util.function.Consumer<java.net.http.HttpResponse<java.io.InputStream>> interceptor)Set a custom response interceptor.static java.lang.StringurlEncode(java.lang.String s)URL encode a string in the UTF-8 encoding.
-
-
-
Constructor Detail
-
ApiClient
public ApiClient()
Create an instance of ApiClient.
-
ApiClient
public ApiClient(java.net.http.HttpClient.Builder builder, com.fasterxml.jackson.databind.ObjectMapper mapper)Create an instance of ApiClient.In other contexts, note that any settings in a
Configurationwill take precedence over equivalent settings in theHttpClient.Builderhere.- Parameters:
builder- Http client builder.mapper- Object mapper.
-
-
Method Detail
-
requestBuilder
public static java.net.http.HttpRequest.Builder requestBuilder(java.lang.String method, java.lang.String path, Configuration configuration) throws FgaInvalidParameterException- Throws:
FgaInvalidParameterException
-
requestBuilder
public static java.net.http.HttpRequest.Builder requestBuilder(java.lang.String method, java.lang.String path, byte[] body, Configuration configuration) throws FgaInvalidParameterException- Throws:
FgaInvalidParameterException
-
formRequestBuilder
public static java.net.http.HttpRequest.Builder formRequestBuilder(java.lang.String method, java.lang.String path, java.lang.String body, Configuration configuration) throws FgaInvalidParameterExceptionCreates aHttpRequest.Builderfor ax-www-form-urlencodedrequest.- Parameters:
method- the HTTP method to be make.path- the URL path.body- the request body. It must be URL-encoded.configuration- the client configuration.- Returns:
- a configured builder.
- Throws:
FgaInvalidParameterException
-
urlEncode
public static java.lang.String urlEncode(java.lang.String s)
URL encode a string in the UTF-8 encoding.- Parameters:
s- String to encode.- Returns:
- URL-encoded representation of the input string.
-
createDefaultObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper createDefaultObjectMapper()
-
getDefaultBaseUri
protected java.lang.String getDefaultBaseUri()
-
createDefaultHttpClientBuilder
protected java.net.http.HttpClient.Builder createDefaultHttpClientBuilder()
-
setHttpClientBuilder
public ApiClient setHttpClientBuilder(java.net.http.HttpClient.Builder builder)
Set a customHttpClient.Builderobject to use when creating theHttpClientthat is used by the API client.In other contexts, note that any settings in a
Configurationwill take precedence over equivalent settings in theHttpClient.Builderhere.- Parameters:
builder- Custom client builder.- Returns:
- This object.
-
getHttpClient
public java.net.http.HttpClient getHttpClient()
Get anHttpClientbased on the currentHttpClient.Builder.The returned object is immutable and thread-safe.
- Returns:
- The HTTP client.
-
getHttpClientBuilder
public java.net.http.HttpClient.Builder getHttpClientBuilder()
Get the currentHttpClient.Builder.The returned object is immutable and thread-safe.
- Returns:
- The HTTP client.
-
setObjectMapper
public ApiClient setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
Set a customObjectMapperto serialize and deserialize the request and response bodies.- Parameters:
mapper- Custom object mapper.- Returns:
- This object.
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Get a copy of the currentObjectMapper.- Returns:
- A copy of the current object mapper.
-
setRequestInterceptor
public ApiClient setRequestInterceptor(java.util.function.Consumer<java.net.http.HttpRequest.Builder> interceptor)
Set a custom request interceptor.A request interceptor is a mechanism for altering each request before it is sent. After the request has been fully configured but not yet built, the request builder is passed into this function for further modification, after which it is sent out.
This is useful for altering the requests in a custom manner, such as adding headers. It could also be used for logging and monitoring.
- Parameters:
interceptor- A function invoked before creating each request. A value of null resets the interceptor to a no-op.- Returns:
- This object.
-
addRequestInterceptor
public void addRequestInterceptor(java.util.function.Consumer<java.net.http.HttpRequest.Builder> interceptor)
Add a custom request interceptor. This interceptor will be run after any other interceptor(s) already in place.For details on request interceptors, see
setRequestInterceptor(Consumer)- Parameters:
interceptor- A function invoked before creating each request. A value of null resets the interceptor to a no-op.
-
getRequestInterceptor
public java.util.function.Consumer<java.net.http.HttpRequest.Builder> getRequestInterceptor()
Get the custom interceptor.- Returns:
- The custom interceptor that was set, or null if there isn't any.
-
setResponseInterceptor
public ApiClient setResponseInterceptor(java.util.function.Consumer<java.net.http.HttpResponse<java.io.InputStream>> interceptor)
Set a custom response interceptor.This is useful for logging, monitoring or extraction of header variables
- Parameters:
interceptor- A function invoked before creating each request. A value of null resets the interceptor to a no-op.- Returns:
- This object.
-
getResponseInterceptor
public java.util.function.Consumer<java.net.http.HttpResponse<java.io.InputStream>> getResponseInterceptor()
Get the custom response interceptor.- Returns:
- The custom interceptor that was set, or null if there isn't any.
-
setAsyncResponseInterceptor
public ApiClient setAsyncResponseInterceptor(java.util.function.Consumer<java.net.http.HttpResponse<java.lang.String>> interceptor)
Set a custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.This is useful for logging, monitoring or extraction of header variables
- Parameters:
interceptor- A function invoked before creating each request. A value of null resets the interceptor to a no-op.- Returns:
- This object.
-
getAsyncResponseInterceptor
public java.util.function.Consumer<java.net.http.HttpResponse<java.lang.String>> getAsyncResponseInterceptor()
Get the custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.- Returns:
- The custom interceptor that was set, or null if there isn't any.
-
-