Skip to content

Commit 4dd51a8

Browse files
SentryManrbygrave
andauthored
[client] Update Javadocs (#643)
* update javadocs * Update HttpAsyncResponse.java --------- Co-authored-by: Rob Bygrave <robin.bygrave@gmail.com>
1 parent ae13018 commit 4dd51a8

File tree

6 files changed

+69
-60
lines changed

6 files changed

+69
-60
lines changed

http-client/src/main/java/io/avaje/http/client/AuthToken.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,26 @@
55

66
/**
77
* Represents an Authorization Bearer token that can be held on the context.
8-
* <p>
9-
* Typically the token will be valid for a period and then expire.
108
*/
119
public interface AuthToken {
1210

1311
/**
14-
* Return the Authorization bearer token.
12+
* The Authorization bearer token.
1513
*/
1614
String token();
1715

1816
/**
19-
* Return true if the token has expired or is no longer valid.
17+
* Whether the token has expired or no longer valid.
2018
*/
2119
boolean isExpired();
2220

2321
/**
24-
* Return the duration until expiry.
22+
* Duration until expiration.
2523
*/
2624
Duration expiration();
2725

2826
/**
29-
* Create an return a AuthToken with the given token and time it is valid until.
27+
* Create an AuthToken with the given token and when it expires.
3028
*/
3129
static AuthToken of(String token, Instant validUntil) {
3230
return new Basic(token, validUntil);

http-client/src/main/java/io/avaje/http/client/AuthTokenProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.avaje.http.client;
22

33
/**
4-
* Use to obtain an Authorization bearer token that is expected to be used.
4+
* Use to obtain an Authorization bearer token used for authenticated requests.
55
*
66
* <pre>{@code
77
*
@@ -33,7 +33,7 @@ public interface AuthTokenProvider {
3333
/**
3434
* Obtain a new Authorization token.
3535
*
36-
* @param tokenRequest A new request to obtain an Authorisation token
36+
* @param tokenRequest A new request to obtain an Authorization token
3737
*/
3838
AuthToken obtainToken(HttpClientRequest tokenRequest);
3939

http-client/src/main/java/io/avaje/http/client/BodyAdapter.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@
33
import java.lang.reflect.Type;
44
import java.util.List;
55

6-
/**
7-
* Adaptor between beans and content of a request or response.
8-
* <p>
9-
* Typically converts between beans as JSON content.
10-
*/
6+
/** Adapter between beans and content of a request or response. */
117
public interface BodyAdapter {
128

139
/**
14-
* Return a BodyWriter to write beans of this type as request content.
10+
* BodyWriter to write beans of this type as request content.
1511
*
1612
* @param type The type of the bean this writer is for
1713
*/
1814
<T> BodyWriter<T> beanWriter(Class<?> type);
1915

2016
/**
21-
* Return a BodyWriter to write beans of this type as request content.
17+
* BodyWriter to write beans of this type as request content.
2218
*
2319
* @param type The type of the bean this writer is for
2420
*/
@@ -27,32 +23,32 @@ default <T> BodyWriter<T> beanWriter(Type type) {
2723
}
2824

2925
/**
30-
* Return a BodyReader to read response content and convert to a bean.
26+
* BodyReader to read response content and convert to a bean.
3127
*
32-
* @param type The bean type to convert the content to.
28+
* @param type type to convert the content to.
3329
*/
3430
<T> BodyReader<T> beanReader(Class<T> type);
3531

3632
/**
37-
* Return a BodyReader to read response content and convert to a bean.
33+
* BodyReader to read response content and convert to a bean.
3834
*
39-
* @param type The bean type to convert the content to.
35+
* @param type type to convert the content to.
4036
*/
4137
default <T> BodyReader<T> beanReader(Type type) {
4238
throw new UnsupportedOperationException("java.lang.reflect.Type is not supported for this adapter");
4339
}
4440

4541
/**
46-
* Return a BodyReader to read response content and convert to a list of beans.
42+
* BodyReader to read response content and convert to a list of beans.
4743
*
48-
* @param type The bean type to convert the content to.
44+
* @param type type to convert the content to.
4945
*/
5046
<T> BodyReader<List<T>> listReader(Class<T> type);
5147

5248
/**
53-
* Return a BodyReader to read response content and convert to a list of beans.
49+
* BodyReader to read response content and convert to a list of beans.
5450
*
55-
* @param type The bean type to convert the content to.
51+
* @param type type to convert the content to.
5652
*/
5753
default <T> BodyReader<List<T>> listReader(Type type) {
5854
throw new UnsupportedOperationException("java.lang.reflect.Type is not supported for this adapter");

http-client/src/main/java/io/avaje/http/client/BodyContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.avaje.http.client;
22

33
/**
4-
* Content of request or response body used for adapting to beans.
4+
* Content of request or response body.
55
* <p>
66
* This is not used for streaming content.
77
*/

http-client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,38 @@
6262
public interface HttpAsyncResponse {
6363

6464
/**
65-
* Process the response with check for 200 range status code
66-
* returning as {@literal HttpResponse<Void>}.
67-
* <p>
68-
* Unlike {@link #asDiscarding()} this request will read any response
69-
* content as bytes with the view that the response content can be
70-
* an error message that could be read via for example
71-
* {@link HttpException#bean(Class)}.
72-
* <p>
73-
* Will throw an HttpException if the status code is in the
74-
* error range allowing the caller to access the error message
75-
* body via for example {@link HttpException#bean(Class)}
76-
* <p>
77-
* This is intended to be used for POST, PUT, DELETE requests
78-
* where the caller is only interested in the response body
79-
* when an error occurs (status code not in 200 range).
80-
*
81-
* <pre>{@code
82-
*
83-
* client.request()
84-
* .path("hello/world")
85-
* .GET()
86-
* .async().asVoid()
87-
* .whenComplete((hres, throwable) -> {
88-
*
89-
* if (throwable != null) {
65+
* Process the response with check for 200 range status code returning as {@literal
66+
* HttpResponse<Void>}.
9067
*
91-
* // if throwable.getCause() is a HttpException for status code >= 300
92-
* HttpException httpException = (HttpException) throwable.getCause();
93-
* int status = httpException.statusCode();
68+
* <p>Unlike {@link #asDiscarding()}, this request will read any response content as bytes with
69+
* the view that the response content can be an error message that could be read via for example
70+
* {@link HttpException#bean(Class)}.
9471
*
95-
* // convert json error response body to a bean
96-
* ErrorResponse errorResponse = httpException.bean(ErrorResponse.class);
97-
* ...
98-
* } else {
99-
* int statusCode = hres.statusCode();
100-
* ...
101-
* }
102-
* });
72+
* @throws HttpException if the status code is in the error range allowing the caller to access
73+
* the error message body via for example {@link HttpException#bean(Class)}
74+
* <p>This is intended to be used for POST, PUT, DELETE requests where the caller is only
75+
* interested in the response body when an error occurs (status code not in 200 range).
76+
* <pre>{@code
77+
* client.request()
78+
* .path("hello/world")
79+
* .GET()
80+
* .async().asVoid()
81+
* .whenComplete((hres, throwable) -> {
82+
*
83+
* if (throwable != null) {
84+
*
85+
* // if throwable.getCause() is a HttpException for status code >= 300
86+
* HttpException httpException = (HttpException) throwable.getCause();
87+
* int status = httpException.statusCode();
88+
*
89+
* // convert json error response body to a bean
90+
* ErrorResponse errorResponse = httpException.bean(ErrorResponse.class);
91+
* ...
92+
* } else {
93+
* int statusCode = hres.statusCode();
94+
* ...
95+
* }
96+
* });
10397
*
10498
* }</pre>
10599
*/

http-client/src/main/java/module-info.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/**
2+
* Provides a HTTP client backed by java's built in {@link java.net.http.HttpClient} with support for adapting body content
3+
* (like JSON) to java types.
4+
* <p>
5+
* Uses the Java http client
6+
*
7+
* <pre>{@code
8+
*
9+
* HttpClient client = HttpClient.builder()
10+
* .baseUrl("http://localhost:8080")
11+
* .bodyAdapter(new JacksonBodyAdapter())
12+
* .build();
13+
*
14+
* HelloDto dto = client.request()
15+
* .path("hello")
16+
* .queryParam("say", "Whats up")
17+
* .GET()
18+
* .bean(HelloDto.class);
19+
*
20+
* }</pre>
21+
*/
122
module io.avaje.http.client {
223

324
uses io.avaje.http.client.HttpClient.GeneratedComponent;

0 commit comments

Comments
 (0)