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