View Javadoc
1   package ca.uhn.fhir.rest.client.api;
2   
3   import java.util.List;
4   
5   /*
6    * #%L
7    * HAPI FHIR - Core Library
8    * %%
9    * Copyright (C) 2014 - 2018 University Health Network
10   * %%
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   * 
15   * http://www.apache.org/licenses/LICENSE-2.0
16   * 
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License.
22   * #L%
23   */
24  
25  import org.hl7.fhir.instance.model.api.IBaseResource;
26  
27  import ca.uhn.fhir.context.FhirContext;
28  import ca.uhn.fhir.rest.api.EncodingEnum;
29  import ca.uhn.fhir.rest.api.SummaryEnum;
30  
31  public interface IRestfulClient {
32  
33  	/**
34  	 * Retrieve the contents at the given URL and parse them as a resource. This
35  	 * method could be used as a low level implementation of a read/vread/search
36  	 * operation.
37  	 * 
38  	 * @param theResourceType
39  	 *           The resource type to parse
40  	 * @param theUrl
41  	 *           The URL to load
42  	 * @return The parsed resource
43  	 */
44  	<T extends IBaseResource> T fetchResourceFromUrl(Class<T> theResourceType, String theUrl);
45  
46  	/**
47  	 * Returns the encoding that will be used on requests. Default is <code>null</code>, which means the client will not
48  	 * explicitly request an encoding. (This is standard behaviour according to the FHIR specification)
49  	 */
50  	EncodingEnum getEncoding();
51  
52  	/**
53  	 * Returns the FHIR context associated with this client
54  	 */
55  	FhirContext getFhirContext();
56  
57  	/**
58  	 * Do not call this method in client code. It is a part of the internal HAPI API and
59  	 * is subject to change!
60  	 */
61  	IHttpClient getHttpClient();
62  
63  	/**
64  	 * Returns the client interceptors that have been registered with this client
65  	 */
66  	List<IClientInterceptor> getInterceptors();
67  
68  	/**
69  	 * Base URL for the server, with no trailing "/"
70  	 */
71  	String getServerBase();
72  
73  	/**
74  	 * Register a new interceptor for this client. An interceptor can be used to add additional
75  	 * logging, or add security headers, or pre-process responses, etc.
76  	 */
77  	void registerInterceptor(IClientInterceptor theInterceptor);
78  
79  	/**
80  	 * Specifies that the client should use the given encoding to do its
81  	 * queries. This means that the client will append the "_format" param
82  	 * to GET methods (read/search/etc), and will add an appropriate header for
83  	 * write methods.
84  	 * 
85  	 * @param theEncoding
86  	 *           The encoding to use in the request, or <code>null</code> not specify
87  	 *           an encoding (which generally implies the use of XML). The default is <code>null</code>.
88  	 */
89  	void setEncoding(EncodingEnum theEncoding);
90  
91  	/**
92  	 * Specifies that the client should request that the server respond with "pretty printing"
93  	 * enabled. Note that this is a non-standard parameter, not all servers will
94  	 * support it.
95  	 * 
96  	 * @param thePrettyPrint
97  	 *           The pretty print flag to use in the request (default is <code>false</code>)
98  	 */
99  	void setPrettyPrint(Boolean thePrettyPrint);
100 
101 	/**
102 	 * If not set to <code>null</code>, specifies a value for the <code>_summary</code> parameter
103 	 * to be applied globally on this client.
104 	 */
105 	void setSummary(SummaryEnum theSummary);
106 
107 	/**
108 	 * Remove an intercaptor that was previously registered using {@link IRestfulClient#registerInterceptor(IClientInterceptor)}
109 	 */
110 	void unregisterInterceptor(IClientInterceptor theInterceptor);
111 
112 }