Interface RestApi
- All Known Implementing Classes:
RestApiBase
,VaultRestApi
public interface RestApi
JSON based REST API operations.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
RestApi.Builder<B extends RestApi.Builder<B,
T>, T extends RestApi> Base builder for REST APIs. -
Method Summary
Modifier and TypeMethodDescriptiondefault <T extends ApiResponse>
Tdelete
(String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Delete without a response entity.default <R,
T extends ApiOptionalResponse<R>>
Tget
(String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, JsonObject, R> responseBuilder) Get with an optional response.default <R,
T extends ApiOptionalResponse<R>>
TgetBytes
(String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, byte[], R> responseBuilder) Get bytes with an optional response.default <R,
T extends ApiOptionalResponse<R>>
TgetEntityStream
(String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, InputStream, R> responseBuilder) Get with a response consisting of a stream.<T extends ApiResponse>
Tinvoke
(Method method, String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Invoke a request that is not expected to yield an entity.<T extends ApiResponse>
TinvokeBytesRequest
(Method method, String path, ApiRequest<?> request, InputStream is, ApiResponse.Builder<?, T> responseBuilder) The request media type should be provided in request, falls back toMediaTypes.APPLICATION_OCTET_STREAM
.<R,
T extends ApiOptionalResponse<R>>
TinvokeBytesResponse
(Method method, String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, byte[], R> responseBuilder) Invoke API call that is expected to return bytes.<R,
T extends ApiOptionalResponse<R>>
TinvokeEntityResponse
(Method method, String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, InputStream, R> responseBuilder) Invoke API call that is expected to return bytes as a publisher.<R,
T extends ApiOptionalResponse<R>>
TinvokeOptional
(Method method, String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, JsonObject, R> responseBuilder) Invoke a request that may yield an entity.<T extends ApiEntityResponse>
TinvokeWithResponse
(Method method, String path, ApiRequest<?> request, ApiEntityResponse.Builder<?, T, JsonObject> responseBuilder) Invoke a request that is expected to yield an entity.default <T extends ApiResponse>
Tpost
(String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Post without a response entity.default <T extends ApiResponse>
Tput
(String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Put without a response entity.
-
Method Details
-
get
default <R,T extends ApiOptionalResponse<R>> T get(String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, JsonObject, R> responseBuilder) Get with an optional response. In case the call returnsStatus.NOT_FOUND_404
this would return an empty optional entity, rather than fail. This may also be the case for requests that useIf-Modified-Since
that return aStatus.NOT_MODIFIED_304
response code.- Type Parameters:
R
- type of the optional part of the responseT
- type of the response- Parameters:
path
- path to invokerequest
- request to useresponseBuilder
- builder with appropriate response processor- Returns:
- response
-
getEntityStream
default <R,T extends ApiOptionalResponse<R>> T getEntityStream(String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, InputStream, R> responseBuilder) Get with a response consisting of a stream.- Type Parameters:
R
- type of the optional part of the responseT
- type of the response- Parameters:
path
- path to invokerequest
- request to useresponseBuilder
- builder with appropriate response processor- Returns:
- response
-
getBytes
default <R,T extends ApiOptionalResponse<R>> T getBytes(String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, byte[], R> responseBuilder) Get bytes with an optional response.- Type Parameters:
R
- type of the optional part of the responseT
- type of the response- Parameters:
path
- path to invokerequest
- request to useresponseBuilder
- builder with appropriateApiOptionalResponse.BuilderBase.entityProcessor(java.util.function.Function)
- Returns:
- response, that may or may not contain an entity (for 404 the entity would be empty)
-
post
default <T extends ApiResponse> T post(String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Post without a response entity.- Type Parameters:
T
- type of the response- Parameters:
path
- path to invokerequest
- request to use, should be an instance ofApiJsonRequest
if an entity is desiredresponseBuilder
- builder to construct response from API call- Returns:
- response
-
put
default <T extends ApiResponse> T put(String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Put without a response entity.- Type Parameters:
T
- type of the response- Parameters:
path
- path to invokerequest
- request to use, should be an instance ofApiJsonRequest
if an entity is desiredresponseBuilder
- builder to construct response from API call- Returns:
- response
-
delete
default <T extends ApiResponse> T delete(String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Delete without a response entity.- Type Parameters:
T
- type of the response- Parameters:
path
- path to invokerequest
- request to use, should be an instance ofApiJsonRequest
if an entity is desiredresponseBuilder
- builder to construct response from API call- Returns:
- response
-
invoke
<T extends ApiResponse> T invoke(Method method, String path, ApiRequest<?> request, ApiResponse.Builder<?, T> responseBuilder) Invoke a request that is not expected to yield an entity.- Type Parameters:
T
- type of the response- Parameters:
method
- HTTP method to invokepath
- path to invokerequest
- request to use, should be an instance ofApiJsonRequest
if and entity is desiredresponseBuilder
- builder to construct response from API call- Returns:
- response
-
invokeWithResponse
<T extends ApiEntityResponse> T invokeWithResponse(Method method, String path, ApiRequest<?> request, ApiEntityResponse.Builder<?, T, JsonObject> responseBuilder) Invoke a request that is expected to yield an entity.- Type Parameters:
T
- type of the response- Parameters:
method
- HTTP method to invokepath
- path to invokerequest
- request to use, should be an instance ofApiJsonRequest
if and entity is desiredresponseBuilder
- builder to construct response from API call- Returns:
- future with entity and metadata if successful, future with error otherwise
-
invokeBytesRequest
<T extends ApiResponse> T invokeBytesRequest(Method method, String path, ApiRequest<?> request, InputStream is, ApiResponse.Builder<?, T> responseBuilder) The request media type should be provided in request, falls back toMediaTypes.APPLICATION_OCTET_STREAM
.- Type Parameters:
T
- type of the response- Parameters:
method
- method to invokepath
- path to invokerequest
- request used to configure query parameters and headersis
- entity bytesresponseBuilder
- builder to construct response from API call- Returns:
- future with the response or error
-
invokeEntityResponse
<R,T extends ApiOptionalResponse<R>> T invokeEntityResponse(Method method, String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, InputStream, R> responseBuilder) Invoke API call that is expected to return bytes as a publisher.The accepted media type must be provided in request, falls back to
MediaTypes.APPLICATION_OCTET_STREAM
.- Type Parameters:
R
- type of the optional part of the responseT
- type of the response- Parameters:
method
- method to invokepath
- path to invokerequest
- request used to configure query parameters and headersresponseBuilder
- builder to construct response from API call with appropriate processor to handle the returned publisher- Returns:
- future with the response
-
invokeBytesResponse
<R,T extends ApiOptionalResponse<R>> T invokeBytesResponse(Method method, String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, byte[], R> responseBuilder) Invoke API call that is expected to return bytes. This method collects all bytes in memory, so it cannot be used for large data. SeeinvokeEntityResponse(io.helidon.http.Method, String, ApiRequest, BuilderBase)
.The accepted media type must be provided in request, falls back to
MediaTypes.APPLICATION_OCTET_STREAM
.- Type Parameters:
R
- type of the optional part of the responseT
- type of the response- Parameters:
method
- method to invokepath
- path to invokerequest
- request used to configure query parameters and headersresponseBuilder
- builder to construct response from API call with appropriate processor to handle the returned bytes- Returns:
- response
-
invokeOptional
<R,T extends ApiOptionalResponse<R>> T invokeOptional(Method method, String path, ApiRequest<?> request, ApiOptionalResponse.BuilderBase<?, T, JsonObject, R> responseBuilder) Invoke a request that may yield an entity. The entity is expected to be missing ifStatus.NOT_FOUND_404
is returned by the API call (and for some other cases, such as not modified).- Type Parameters:
R
- type of the optional part of the responseT
- type of the response- Parameters:
method
- HTTP method to invokepath
- path to invokerequest
- request to use, should be an instance ofApiJsonRequest
if and entity is desiredresponseBuilder
- response builder with appropriate processor to create the optional part- Returns:
- response
-