Skip to content

Commit 9e9baff

Browse files
committed
Improved EntryEndpoint constructor argument order and documentation
1 parent 3d36117 commit 9e9baff

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

endpoints/Endpoint.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,20 @@ export class Endpoint {
3535
* Creates a new endpoint.
3636
* @param referrer The endpoint used to navigate to this one. Must be defined except for top-level endpoint.
3737
* @param uri The HTTP URI of the remote element. May be relative if `referrer` is defined.
38-
* @param httpClient The HTTP client used to communicate with the remote resource. Taken from `referrer` instead if it is defined.
3938
* @param serializer Controls the serialization of entities sent to and received from the server. Taken from `referrer` instead if it is defined.
4039
* @param errorHandler Handles errors in responses. Taken from `referrer` instead if it is defined.
4140
* @param linkExtractor Extracts links from responses. Taken from `referrer` instead if it is defined.
41+
* @param httpClient The HTTP client used to communicate with the remote resource. Taken from `referrer` instead if it is defined.
4242
*/
4343
constructor(
4444
referrer: Endpoint | undefined,
4545
uri: URL | string,
46-
httpClient?: HttpClient,
4746
serializer?: Serializer,
4847
errorHandler?: ErrorHandler,
49-
linkExtractor?: LinkExtractor) {
48+
linkExtractor?: LinkExtractor,
49+
httpClient?: HttpClient) {
5050
if (referrer) {
5151
this.uri = (typeof uri === "string") ? referrer.join(uri) : uri;
52-
if (httpClient)
53-
throw new Error("httpClient must not be specified if referrer is not specified.");
54-
this.httpClient = referrer.httpClient;
5552
if (serializer)
5653
throw new Error("serializer must not be specified if referrer is not specified.");
5754
this.serializer = referrer.serializer;
@@ -61,11 +58,11 @@ export class Endpoint {
6158
if (linkExtractor)
6259
throw new Error("linkExtractor must not be specified if referrer is not specified.");
6360
this.linkExtractor = referrer.linkExtractor;
61+
if (httpClient)
62+
throw new Error("httpClient must not be specified if referrer is not specified.");
63+
this.httpClient = referrer.httpClient;
6464
} else {
6565
this.uri = (typeof uri === "string") ? new URL(uri) : uri;
66-
if (!httpClient)
67-
throw new Error("httpClient must be specified if referrer is not specified.");
68-
this.httpClient = httpClient;
6966
if (!serializer)
7067
throw new Error("serializer must be specified if referrer is not specified.");
7168
this.serializer = serializer;
@@ -75,6 +72,9 @@ export class Endpoint {
7572
if (!linkExtractor)
7673
throw new Error("linkExtractor must be specified if referrer is not specified.");
7774
this.linkExtractor = linkExtractor;
75+
if (!httpClient)
76+
throw new Error("httpClient must be specified if referrer is not specified.");
77+
this.httpClient = httpClient;
7878
}
7979
}
8080

endpoints/EntryEndpoint.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ import { LinkExtractor, AggregateLinkExtractor, HeaderLinkExtractor, HalLinkExtr
1010
export class EntryEndpoint extends Endpoint {
1111
/**
1212
* Creates a new entry endpoint.
13-
* @param uri The base URI of the REST API. Missing trailing slash will be appended automatically
14-
* @param httpClient The HTTP client used to communicate with the REST API.
15-
* @param serializer Controls the serialization of entities sent to and received from the server. Defaults to {@link JsonSerializer} if unset.</param>
16-
* @param errorHandler Handles errors in HTTP responses. Defaults to {@link DefaultErrorHandler} if unset.</param>
17-
* @param linkExtractor Detects links in HTTP responses. Combines {@link HeaderLinkExtractor} and {@link HalLinkExtractor} if unset.</param>
13+
* @param uri The base URI of the REST API.<br>Missing trailing slash will be appended automatically.
14+
* @param serializer Controls the serialization of entities sent to and received from the server.<br>Defaults to {@link JsonSerializer} if undefined.
15+
* @param errorHandler Handles errors in HTTP responses.<br>Defaults to {@link DefaultErrorHandler} if undefined.
16+
* @param linkExtractor Detects links in HTTP responses.<br>Defaults to {@link HeaderLinkExtractor} and {@link HalLinkExtractor} combined via {@link AggregateLinkExtractor} if undefined.
17+
* @param httpClient The HTTP client used to communicate with the REST API.<br>Defaults to {@link FetchHttpClient} if undefined.
1818
*/
1919
constructor(
2020
uri: URL | string,
21-
httpClient?: HttpClient,
2221
serializer?: Serializer,
2322
errorHandler?: ErrorHandler,
24-
linkExtractor?: LinkExtractor) {
23+
linkExtractor?: LinkExtractor,
24+
httpClient?: HttpClient) {
2525
super(undefined,
2626
Endpoint.ensureTrailingSlash(uri),
27-
httpClient ?? new FetchHttpClient(),
2827
serializer ?? new JsonSerializer(),
2928
errorHandler ?? new DefaultErrorHandler(),
30-
linkExtractor ?? new AggregateLinkExtractor(new HeaderLinkExtractor(), new HalLinkExtractor()));
29+
linkExtractor ?? new AggregateLinkExtractor(new HeaderLinkExtractor(), new HalLinkExtractor()),
30+
httpClient ?? new FetchHttpClient());
3131

3232
for (const mediaType of this.serializer.supportedMediaTypes) {
3333
this.httpClient.defaultHeaders.append(HttpHeader.Accept, mediaType);

0 commit comments

Comments
 (0)