22[ ![ Maven Central] ( https://img.shields.io/maven-central/v/io.avaje/avaje-http-client.svg?label=Maven%20Central )] ( https://mvnrepository.com/artifact/io.avaje/avaje-http-client )
33[ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-blue.svg )] ( https://github.com/avaje/avaje-http-client/blob/master/LICENSE )
44
5- # avaje-http-client
6-
7- Documentation at [ avaje.io/http-client] ( https://avaje.io/http-client/ )
5+ # [ Avaje-HTTP-Client] ( https://avaje.io/http-client/ )
86
97A lightweight wrapper to the [ JDK 11+ Java Http Client] ( http://openjdk.java.net/groups/net/httpclient/intro.html )
108
@@ -28,14 +26,14 @@ A lightweight wrapper to the [JDK 11+ Java Http Client](http://openjdk.java.net/
2826</dependency >
2927```
3028
31- ### Create HttpClientContext
29+ ### Create HttpClient
3230
33- Create a HttpClientContext with a baseUrl, Jackson or Gson based JSON
31+ Create a HttpClient with a baseUrl, Jackson or Gson based JSON
3432 body adapter, logger.
3533
3634``` java
37- public HttpClientContext client() {
38- return HttpClientContext . builder()
35+ public HttpClient client() {
36+ return HttpClient . builder()
3937 .baseUrl(baseUrl)
4038 .bodyAdapter(new JsonbBodyAdapter ())
4139 // .bodyAdapter(new JacksonBodyAdapter(new ObjectMapper()))
@@ -47,7 +45,7 @@ Create a HttpClientContext with a baseUrl, Jackson or Gson based JSON
4745
4846## Requests
4947
50- From HttpClientContext :
48+ From HttpClient :
5149 - Create a request
5250 - Build the url via path(), matrixParam(), queryParam()
5351 - Optionally set headers(), cookies() etc
@@ -78,15 +76,15 @@ From HttpClientContext:
7876
7977#### Example GET as String
8078``` java
81- HttpResponse<String > hres = clientContext . request()
79+ HttpResponse<String > hres = client . request()
8280 .path(" hello" )
8381 . GET ()
8482 .asString();
8583```
8684
8785#### Example GET as JSON marshalling into a java class/dto
8886``` java
89- CustomerDto customer = clientContext . request()
87+ CustomerDto customer = client . request()
9088 .path(" customers" ). path(42 )
9189 . GET ()
9290 .bean(CustomerDto . class);
@@ -98,7 +96,7 @@ CustomerDto customer = clientContext.request()
9896- In the example below hres is of type HttpResponse< ; String> ;
9997
10098``` java
101- clientContext . request()
99+ client . request()
102100 .path(" hello" )
103101 . GET ()
104102 .async(). asString() // CompletableFuture<HttpResponse<String>>
@@ -173,7 +171,7 @@ When sending body content we can use:
173171
174172#### GET as String
175173``` java
176- HttpResponse<String > hres = clientContext . request()
174+ HttpResponse<String > hres = client . request()
177175 .path(" hello" )
178176 . GET ()
179177 .asString();
@@ -185,7 +183,7 @@ HttpResponse<String> hres = clientContext.request()
185183 - In the example below hres is of type HttpResponse< ; String> ;
186184
187185``` java
188- clientContext . request()
186+ client . request()
189187 .path(" hello" )
190188 . GET ()
191189 .async(). asString()
@@ -205,23 +203,23 @@ clientContext.request()
205203
206204#### GET as json to single bean
207205``` java
208- Customer customer = clientContext . request()
206+ Customer customer = client . request()
209207 .path(" customers" ). path(42 )
210208 . GET ()
211209 .bean(Customer . class);
212210```
213211
214212#### GET as json to a list of beans
215213``` java
216- List<Customer > list = clientContext . request()
214+ List<Customer > list = client . request()
217215 .path(" customers" )
218216 . GET ()
219217 .list(Customer . class);
220218```
221219
222220#### GET as ` application/x-json-stream ` as a stream of beans
223221``` java
224- Stream<Customer > stream = clientContext . request()
222+ Stream<Customer > stream = client . request()
225223 .path(" customers/all" )
226224 . GET ()
227225 .stream(Customer . class);
@@ -232,7 +230,7 @@ Stream<Customer> stream = clientContext.request()
232230``` java
233231Hello bean = new Hello (42 , " rob" , " other" );
234232
235- HttpResponse<Void > res = clientContext . request()
233+ HttpResponse<Void > res = client . request()
236234 .path(" hello" )
237235 .body(bean)
238236 . POST ()
@@ -248,7 +246,7 @@ Multiple calls to `path()` append with a `/`. This is make it easier to build a
248246programmatically and also build paths that include ` matrixParam() `
249247
250248``` java
251- HttpResponse<String > res = clientContext . request()
249+ HttpResponse<String > res = client . request()
252250 .path(" customers" )
253251 .path(" 42" )
254252 .path(" contacts" )
@@ -257,15 +255,15 @@ HttpResponse<String> res = clientContext.request()
257255
258256// is the same as ...
259257
260- HttpResponse<String > res = clientContext . request()
258+ HttpResponse<String > res = client . request()
261259 .path(" customers/42/contacts" )
262260 . GET ()
263261 .asString();
264262```
265263
266264#### MatrixParam
267265``` java
268- HttpResponse<String > httpRes = clientContext . request()
266+ HttpResponse<String > httpRes = client . request()
269267 .path(" books" )
270268 .matrixParam(" author" , " rob" )
271269 .matrixParam(" country" , " nz" )
@@ -277,7 +275,7 @@ HttpResponse<String> httpRes = clientContext.request()
277275
278276#### QueryParam
279277``` java
280- List<Product > beans = clientContext . request()
278+ List<Product > beans = client . request()
281279 .path(" products" )
282280 .queryParam(" sortBy" , " name" )
283281 .queryParam(" maxCount" , " 100" )
@@ -287,7 +285,7 @@ List<Product> beans = clientContext.request()
287285
288286#### FormParam
289287``` java
290- HttpResponse<Void > res = clientContext . request()
288+ HttpResponse<Void > res = client . request()
291289 .path(" register/user" )
292290 .formParam(" name" , " Bazz" )
293291 .formParam(" email" , " user@foo.com" )
@@ -355,7 +353,7 @@ The `bean()`, `list()` and `stream()` responses throw a `HttpException` if the s
355353
356354``` java
357355
358- clientContext . request()
356+ client . request()
359357 .path(" hello/world" )
360358 . GET ()
361359 .async(). asDiscarding()
@@ -374,7 +372,7 @@ clientContext.request()
374372### .async().asString() - HttpResponse< ; String> ;
375373
376374``` java
377- clientContext . request()
375+ client . request()
378376 .path(" hello/world" )
379377 . GET ()
380378 .async(). asString()
@@ -393,7 +391,7 @@ clientContext.request()
393391### .async().bean(HelloDto.class)
394392
395393``` java
396- clientContext . request()
394+ client . request()
397395 ...
398396 . POST (). async()
399397 .bean(HelloDto . class)
@@ -420,7 +418,7 @@ clientContext.request()
420418The example below is a line subscriber processing response content line by line.
421419
422420``` java
423- CompletableFuture<HttpResponse<Void > > future = clientContext . request()
421+ CompletableFuture<HttpResponse<Void > > future = client . request()
424422 .path(" hello/lineStream" )
425423 . GET (). async()
426424 .handler(HttpResponse . BodyHandlers . fromLineSubscriber(new Flow .Subscriber<> () {
@@ -460,7 +458,7 @@ choose `async()` to execute the request asynchronously.
460458
461459``` java
462460HttpCall<List<Customer > > call =
463- clientContext . request()
461+ client . request()
464462 .path(" customers" )
465463 . GET ()
466464 .call(). list(Customer . class);
@@ -484,8 +482,8 @@ header ("Basic Auth").
484482##### Example
485483
486484``` java
487- HttpClientContext clientContext =
488- HttpClientContext . builder()
485+ HttpClient client =
486+ HttpClient . builder()
489487 .baseUrl(baseUrl)
490488 ...
491489 .requestIntercept(new BasicAuthIntercept (" myUsername" , " myPassword" )) < ! -- HERE
@@ -496,7 +494,7 @@ HttpClientContext clientContext =
496494## AuthTokenProvider - Authorization Bearer token
497495
498496For Authorization using ` Bearer ` tokens that are obtained and expire, implement ` AuthTokenProvider `
499- and register that when building the HttpClientContext .
497+ and register that when building the HttpClient .
500498
501499### 1. Implement AuthTokenProvider
502500
@@ -520,10 +518,10 @@ and register that when building the HttpClientContext.
520518 }
521519```
522520
523- ### 2. Register with HttpClientContext
521+ ### 2. Register with HttpClient
524522
525523``` java
526- HttpClientContext ctx = HttpClientContext . builder()
524+ HttpClient client = HttpClient . builder()
527525 .baseUrl(" https://foo" )
528526 ...
529527 .authTokenProvider(new MyAuthTokenProvider ()) < ! -- HERE
@@ -532,7 +530,7 @@ and register that when building the HttpClientContext.
532530
533531### 3. Token obtained and set automatically
534532
535- All requests using the HttpClientContext will automatically get
533+ All requests using the HttpClient will automatically get
536534an ` Authorization ` header with ` Bearer ` token added. The token will be
537535obtained for initial request and then renewed when the token has expired.
538536
0 commit comments