1111import com .meilisearch .sdk .http .response .HttpResponse ;
1212import com .meilisearch .sdk .json .GsonJsonHandler ;
1313import com .meilisearch .sdk .json .JsonHandler ;
14+
1415import java .util .Collections ;
1516import java .util .Map ;
1617
17- /** HTTP client used for API calls to Meilisearch */
18+ /**
19+ * HTTP client used for API calls to Meilisearch
20+ */
1821public class HttpClient {
1922 private final CustomOkHttpClient client ;
2023 private final BasicRequest request ;
@@ -38,7 +41,7 @@ public HttpClient(Config config) {
3841 /**
3942 * Constructor for the HttpClient
4043 *
41- * @param client HttpClient for making calls to server
44+ * @param client HttpClient for making calls to server
4245 * @param request BasicRequest for generating calls to server
4346 */
4447 public HttpClient (CustomOkHttpClient client , BasicRequest request ) {
@@ -57,56 +60,56 @@ public HttpClient(CustomOkHttpClient client, BasicRequest request) {
5760 * @throws MeilisearchException if the response is an error
5861 */
5962 <T > T get (String api , Class <T > targetClass , Class <?>... parameters )
60- throws MeilisearchException {
63+ throws MeilisearchException {
6164 return this .get (api , "" , targetClass , parameters );
6265 }
6366
6467 /**
6568 * Gets the specified resource from the specified path with a given parameter
6669 *
67- * @param api Path to document
70+ * @param api Path to document
6871 * @param param Parameter to be passed
6972 * @return document that was requested
7073 * @throws MeilisearchException if the response is an error
7174 */
7275 <T > T get (String api , String param , Class <T > targetClass , Class <?>... parameters )
73- throws MeilisearchException {
76+ throws MeilisearchException {
7477 HttpRequest requestConfig = request .create (HttpMethod .GET , api + param , this .headers , null );
7578 HttpResponse <T > httpRequest = this .client .get (requestConfig );
7679 HttpResponse <T > httpResponse = response .create (httpRequest , targetClass , parameters );
7780
7881 if (httpResponse .getStatusCode () >= 400 ) {
7982 throw new MeilisearchApiException (
80- jsonHandler .decode (httpRequest .getContent (), APIError .class ));
83+ jsonHandler .decode (httpRequest .getContent (), APIError .class ));
8184 }
8285 return httpResponse .getContent ();
8386 }
8487
8588 /**
8689 * Adds the specified resource to the specified path
8790 *
88- * @param api Path to server
91+ * @param api Path to server
8992 * @param body Query for search
9093 * @return results of the search
9194 * @throws MeilisearchException if the response is an error
9295 */
9396 <S , T > T post (String api , S body , Class <T > targetClass , Class <?>... parameters )
94- throws MeilisearchException {
97+ throws MeilisearchException {
9598 HttpRequest requestConfig = request .create (HttpMethod .POST , api , this .headers , body );
9699 HttpResponse <T > httpRequest = this .client .post (requestConfig );
97100 HttpResponse <T > httpResponse = response .create (httpRequest , targetClass , parameters );
98101
99102 if (httpResponse .getStatusCode () >= 400 ) {
100103 throw new MeilisearchApiException (
101- jsonHandler .decode (httpRequest .getContent (), APIError .class ));
104+ jsonHandler .decode (httpRequest .getContent (), APIError .class ));
102105 }
103106 return httpResponse .getContent ();
104107 }
105108
106109 /**
107110 * Replaces the specified resource with new data to the specified path
108111 *
109- * @param api Path to the requested resource
112+ * @param api Path to the requested resource
110113 * @param body Replacement data for the requested resource
111114 * @return updated resource
112115 * @throws MeilisearchException if the response is an error
@@ -118,15 +121,15 @@ <S, T> T put(String api, S body, Class<T> targetClass) throws MeilisearchExcepti
118121
119122 if (httpResponse .getStatusCode () >= 400 ) {
120123 throw new MeilisearchApiException (
121- jsonHandler .decode (httpRequest .getContent (), APIError .class ));
124+ jsonHandler .decode (httpRequest .getContent (), APIError .class ));
122125 }
123126 return httpResponse .getContent ();
124127 }
125128
126129 /**
127130 * Patch the specified resource with new data to the specified path
128131 *
129- * @param api Path to server
132+ * @param api Path to server
130133 * @param body Query for search
131134 * @return results of the search
132135 * @throws MeilisearchException if the response is an error
@@ -137,7 +140,7 @@ <S, T> T patch(String api, S body, Class<T> targetClass) throws MeilisearchExcep
137140
138141 if (httpResponse .getStatusCode () >= 400 ) {
139142 throw new MeilisearchApiException (
140- jsonHandler .decode (httpResponse .getContent (), APIError .class ));
143+ jsonHandler .decode (httpResponse .getContent (), APIError .class ));
141144 }
142145
143146 return response .create (httpResponse , targetClass ).getContent ();
@@ -154,11 +157,11 @@ <T> T delete(String api, Class<T> targetClass) throws MeilisearchException {
154157 HttpRequest requestConfig = request .create (HttpMethod .DELETE , api , this .headers , null );
155158 HttpResponse <T > httpRequest = this .client .delete (requestConfig );
156159 HttpResponse <T > httpResponse = response .create (httpRequest , targetClass );
157-
158160 if (httpResponse .getStatusCode () >= 400 ) {
159161 throw new MeilisearchApiException (
160- jsonHandler .decode (httpRequest .getContent (), APIError .class ));
162+ jsonHandler .decode (httpRequest .getContent (), APIError .class ));
161163 }
162164 return httpResponse .getContent ();
165+
163166 }
164167}
0 commit comments