001package ca.uhn.fhir.rest.gclient;
002
003import ca.uhn.fhir.rest.api.CacheControlDirective;
004import ca.uhn.fhir.rest.api.EncodingEnum;
005import ca.uhn.fhir.rest.api.RequestFormatParamStyleEnum;
006import ca.uhn.fhir.rest.api.SummaryEnum;
007import org.hl7.fhir.instance.model.api.IBaseResource;
008
009import java.util.List;
010
011/*
012 * #%L
013 * HAPI FHIR - Core Library
014 * %%
015 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
016 * %%
017 * Licensed under the Apache License, Version 2.0 (the "License");
018 * you may not use this file except in compliance with the License.
019 * You may obtain a copy of the License at
020 *
021 *      http://www.apache.org/licenses/LICENSE-2.0
022 *
023 * Unless required by applicable law or agreed to in writing, software
024 * distributed under the License is distributed on an "AS IS" BASIS,
025 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
026 * See the License for the specific language governing permissions and
027 * limitations under the License.
028 * #L%
029 */
030
031
032public interface IClientExecutable<T extends IClientExecutable<?, Y>, Y> {
033
034        /**
035         * If set to true, the client will log the request and response to the SLF4J logger. This can be useful for
036         * debugging, but is generally not desirable in a production situation.
037         *
038         * @deprecated Use the client logging interceptor to log requests and responses instead. See <a href="https://hapifhir.io/hapi-fhir/docs/interceptors/built_in_client_interceptors.html">here</a> for more information.
039         */
040        @Deprecated
041        T andLogRequestAndResponse(boolean theLogRequestAndResponse);
042
043        /**
044         * Sets the <code>Cache-Control</code> header value, which advises the server (or any cache in front of it)
045         * how to behave in terms of cached requests
046         */
047        T cacheControl(CacheControlDirective theCacheControlDirective);
048
049        /**
050         * Request that the server return subsetted resources, containing only the elements specified in the given parameters.
051         * For example: <code>subsetElements("name", "identifier")</code> requests that the server only return
052         * the "name" and "identifier" fields in the returned resource, and omit any others.
053         */
054        T elementsSubset(String... theElements);
055
056        /**
057         * Request that the server respond with JSON via the Accept header and possibly also the
058         * <code>_format</code> parameter if {@link ca.uhn.fhir.rest.client.api.IRestfulClient#setFormatParamStyle(RequestFormatParamStyleEnum) configured to do so}.
059         * <p>
060         * This method will have no effect if {@link #accept(String) a custom Accept header} is specified.
061         * </p>
062         *
063         * @see #accept(String)
064         */
065        T encoded(EncodingEnum theEncoding);
066
067        /**
068         * Request that the server respond with JSON via the Accept header and possibly also the
069         * <code>_format</code> parameter if {@link ca.uhn.fhir.rest.client.api.IRestfulClient#setFormatParamStyle(RequestFormatParamStyleEnum) configured to do so}.
070         * <p>
071         * This method will have no effect if {@link #accept(String) a custom Accept header} is specified.
072         * </p>
073         *
074         * @see #accept(String)
075         * @see #encoded(EncodingEnum)
076         */
077        T encodedJson();
078
079        /**
080         * Request that the server respond with JSON via the Accept header and possibly also the
081         * <code>_format</code> parameter if {@link ca.uhn.fhir.rest.client.api.IRestfulClient#setFormatParamStyle(RequestFormatParamStyleEnum) configured to do so}.
082         * <p>
083         * This method will have no effect if {@link #accept(String) a custom Accept header} is specified.
084         * </p>
085         *
086         * @see #accept(String)
087         * @see #encoded(EncodingEnum)
088         */
089        T encodedXml();
090
091        /**
092         * Set a HTTP header not explicitly defined in FHIR but commonly used in real-world scenarios. One
093         * important example is to set the Authorization header (e.g. Basic Auth or OAuth2-based Bearer auth),
094         * which tends to be cumbersome using {@link ca.uhn.fhir.rest.client.api.IClientInterceptor IClientInterceptors},
095         * particularly when REST clients shall be reused and are thus supposed to remain stateless.
096         * <p>It is the responsibility of the caller to care for proper encoding of the header value, e.g.
097         * using Base64.</p>
098         * <p>This is a short-cut alternative to using a corresponding client interceptor</p>
099         *
100         * @param theHeaderName header name
101         * @param theHeaderValue header value
102         * @return
103         */
104        T withAdditionalHeader(String theHeaderName, String theHeaderValue);
105
106        /**
107         * Actually execute the client operation
108         */
109        Y execute();
110
111        /**
112         * Explicitly specify a custom structure type to attempt to use when parsing the response. This
113         * is useful for invocations where the response is a Bundle/Parameters containing nested resources,
114         * and you want to use specific custom structures for those nested resources.
115         * <p>
116         * See <a href="https://jamesagnew.github.io/hapi-fhir/doc_extensions.html">Profiles and Extensions</a> for more information on using custom structures
117         * </p>
118         */
119        T preferResponseType(Class<? extends IBaseResource> theType);
120
121        /**
122         * Explicitly specify a list of custom structure types to attempt to use (in order from most to
123         * least preferred) when parsing the response. This
124         * is useful for invocations where the response is a Bundle/Parameters containing nested resources,
125         * and you want to use specific custom structures for those nested resources.
126         * <p>
127         * See <a href="https://jamesagnew.github.io/hapi-fhir/doc_extensions.html">Profiles and Extensions</a> for more information on using custom structures
128         * </p>
129         */
130        T preferResponseTypes(List<Class<? extends IBaseResource>> theTypes);
131
132        /**
133         * Request pretty-printed response via the <code>_pretty</code> parameter
134         */
135        T prettyPrint();
136
137        /**
138         * Request that the server modify the response using the <code>_summary</code> param
139         */
140        T summaryMode(SummaryEnum theSummary);
141
142        /**
143         * Specifies a custom <code>Accept</code> header that should be supplied with the
144         * request.
145         * <p>
146         * Note that this method overrides any encoding preferences specified with
147         * {@link #encodedJson()} or {@link #encodedXml()}. It is generally easier to
148         * just use those methods if you simply want to request a specific FHIR encoding.
149         * </p>
150         *
151         * @param theHeaderValue The header value, e.g. "application/fhir+json". Constants such
152         *                       as {@link ca.uhn.fhir.rest.api.Constants#CT_FHIR_XML_NEW} and
153         *                       {@link ca.uhn.fhir.rest.api.Constants#CT_FHIR_JSON_NEW} may
154         *                       be useful. If set to <code>null</code> or an empty string, the
155         *                       default Accept header will be used.
156         * @see #encoded(EncodingEnum)
157         * @see #encodedJson()
158         * @see #encodedXml()
159         */
160        T accept(String theHeaderValue);
161}