@Beta public final class ApiClient extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ApiClient.CollectionFormat
Enum representing the delimiter of a given collection.
|
Constructor and Description |
---|
ApiClient()
Creates an instance of this class.
|
ApiClient(HttpDestinationProperties destination)
Creates an instance of this class given an instance of
HttpDestinationProperties . |
ApiClient(org.springframework.web.client.RestTemplate restTemplate)
Creates an instance of this class given an instance of
RestTemplate . |
Modifier and Type | Method and Description |
---|---|
ApiClient |
addDefaultHeader(String name,
String value)
Add a default header.
|
String |
collectionPathParameterToString(ApiClient.CollectionFormat collectionFormat,
Collection<? extends CharSequence> values)
Formats the specified collection path parameter to a string value.
|
String |
formatDate(Date date)
Format the given Date object into string.
|
Authentication |
getAuthentication(String authName)
Get authentication for the given name.
|
Map<String,Authentication> |
getAuthentications()
Get authentications (key: authentication name, value: authentication).
|
String |
getBasePath()
Get the current base path
|
DateFormat |
getDateFormat()
Get the date format used to parse/format date parameters.
|
org.springframework.util.MultiValueMap<String,String> |
getResponseHeaders()
Gets the response headers of the previous request
|
org.springframework.http.HttpStatus |
getStatusCode()
Gets the status code of the previous request
|
<T> T |
invokeAPI(String path,
org.springframework.http.HttpMethod method,
org.springframework.util.MultiValueMap<String,String> queryParams,
Object body,
org.springframework.http.HttpHeaders headerParams,
org.springframework.util.MultiValueMap<String,Object> formParams,
List<org.springframework.http.MediaType> accept,
org.springframework.http.MediaType contentType,
String[] authNames,
org.springframework.core.ParameterizedTypeReference<T> returnType)
Invoke API by sending HTTP request with the given options.
|
boolean |
isDebugging()
Check that whether debugging is enabled for this API client.
|
boolean |
isJsonMime(org.springframework.http.MediaType mediaType)
Check if the given MIME is a JSON MIME.
|
boolean |
isJsonMime(String mediaType)
Check if the given
String is a JSON MIME. |
org.springframework.util.MultiValueMap<String,String> |
parameterToMultiValueMap(ApiClient.CollectionFormat collectionFormat,
String name,
Object value)
Converts a parameter to a
MultiValueMap for use in REST requests |
String |
parameterToString(Object param)
Format the given parameter object into string.
|
Date |
parseDate(String str)
Parse the given string into Date object.
|
List<org.springframework.http.MediaType> |
selectHeaderAccept(String[] accepts)
Select the Accept header's value from the given accepts array: if JSON exists in the given array, use it;
otherwise use all of them (joining into a string)
|
org.springframework.http.MediaType |
selectHeaderContentType(String[] contentTypes)
Select the Content-Type header's value from the given array: if JSON exists in the given array, use it; otherwise
use the first one of the array.
|
void |
setApiKey(String apiKey)
Helper method to set API key value for the first API key authentication.
|
void |
setApiKeyPrefix(String apiKeyPrefix)
Helper method to set API key prefix for the first API key authentication.
|
ApiClient |
setBasePath(String basePath)
Set the base path, which should include the host
|
ApiClient |
setDateFormat(DateFormat dateFormat)
Set the date format used to parse/format date parameters.
|
void |
setPassword(String password)
Helper method to set password for the first HTTP basic authentication.
|
ApiClient |
setUserAgent(String userAgent)
Set the User-Agent header's value (by adding to the default header map).
|
void |
setUsername(String username)
Helper method to set username for the first HTTP basic authentication.
|
public ApiClient()
@Nonnull public ApiClient(@Nonnull org.springframework.web.client.RestTemplate restTemplate)
RestTemplate
.restTemplate
- An instance of RestTemplate
@Nonnull public ApiClient(@Nonnull HttpDestinationProperties destination)
HttpDestinationProperties
.destination
- An instance of HttpDestinationProperties
@Nonnull public String getBasePath()
@Nonnull public ApiClient setBasePath(@Nonnull String basePath)
basePath
- the base path@Nonnull public org.springframework.http.HttpStatus getStatusCode()
@Nonnull public org.springframework.util.MultiValueMap<String,String> getResponseHeaders()
@Nonnull public Map<String,Authentication> getAuthentications()
@Nonnull public Authentication getAuthentication(@Nonnull String authName)
authName
- The authentication namepublic void setUsername(@Nonnull String username)
username
- the usernamepublic void setPassword(@Nonnull String password)
password
- the passwordpublic void setApiKey(@Nonnull String apiKey)
apiKey
- the API keypublic void setApiKeyPrefix(@Nonnull String apiKeyPrefix)
apiKeyPrefix
- the API key prefix@Nonnull public ApiClient setUserAgent(@Nonnull String userAgent)
userAgent
- the user agent string@Nonnull public ApiClient addDefaultHeader(@Nonnull String name, @Nonnull String value)
name
- The header's namevalue
- The header's valuepublic boolean isDebugging()
@Nonnull public DateFormat getDateFormat()
@Nonnull public ApiClient setDateFormat(@Nonnull DateFormat dateFormat)
dateFormat
- Date format@Nonnull public Date parseDate(@Nonnull String str)
str
- the string to parse@Nonnull public String formatDate(@Nonnull Date date)
date
- the date to format@Nonnull public String parameterToString(@Nonnull Object param)
param
- the object to convert@Nonnull public String collectionPathParameterToString(@Nullable ApiClient.CollectionFormat collectionFormat, @Nonnull Collection<? extends CharSequence> values)
collectionFormat
- The collection format of the parameter.values
- The values of the parameter.@Nonnull public org.springframework.util.MultiValueMap<String,String> parameterToMultiValueMap(@Nullable ApiClient.CollectionFormat collectionFormat, @Nonnull String name, Object value)
MultiValueMap
for use in REST requestscollectionFormat
- The format to convert toname
- The name of the parametervalue
- The parameter's valuepublic boolean isJsonMime(@Nonnull String mediaType)
String
is a JSON MIME.mediaType
- the input MediaTypepublic boolean isJsonMime(@Nonnull org.springframework.http.MediaType mediaType)
mediaType
- the input MediaType@Nullable public List<org.springframework.http.MediaType> selectHeaderAccept(@Nonnull String[] accepts)
accepts
- The accepts array to select from@Nonnull public org.springframework.http.MediaType selectHeaderContentType(@Nonnull String[] contentTypes)
contentTypes
- The Content-Type array to select from@Nullable public <T> T invokeAPI(@Nonnull String path, @Nonnull org.springframework.http.HttpMethod method, @Nullable org.springframework.util.MultiValueMap<String,String> queryParams, @Nullable Object body, @Nullable org.springframework.http.HttpHeaders headerParams, @Nullable org.springframework.util.MultiValueMap<String,Object> formParams, @Nullable List<org.springframework.http.MediaType> accept, @Nullable org.springframework.http.MediaType contentType, @Nullable String[] authNames, @Nonnull org.springframework.core.ParameterizedTypeReference<T> returnType) throws RestRequestException
T
- the return type to usepath
- The sub-path of the HTTP URLmethod
- The request methodqueryParams
- The query parametersbody
- The request body objectheaderParams
- The header parametersformParams
- The form parametersaccept
- The request's Accept headercontentType
- The request's Content-Type headerauthNames
- The authentications to applyreturnType
- The return type into which to deserialize the responseRestRequestException
- Thrown in case an exception occurs during invocation of the REST APICopyright © 2020 SAP SE. All rights reserved.