forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPClientFactory.ts
More file actions
48 lines (43 loc) · 1.7 KB
/
Copy pathHTTPClientFactory.ts
File metadata and controls
48 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module HTTPClientFactory
*/
import { AuthenticationHandler } from "./middleware/AuthenticationHandler";
import { HTTPMessageHandler } from "./middleware/HTTPMessageHandler";
import { HTTPClient } from "./HTTPClient";
import { AuthenticationProvider } from "./IAuthenticationProvider";
import { Middleware } from "./IMiddleware";
/**
* @class
* Class representing HTTPClientFactory
*/
export class HTTPClientFactory {
/**
* @public
* @static
* Creates HTTPClient with default middleware chain
* @param {AuthenticationProvider} authProvider - The authentication provider instance
* @return A HTTPClient instance
*/
public static createWithAuthenticationProvider(authProvider: AuthenticationProvider): HTTPClient {
let authenticationHandler = new AuthenticationHandler(authProvider);
let httpMessageHandler = new HTTPMessageHandler();
authenticationHandler.setNext(httpMessageHandler);
return HTTPClientFactory.createWithMiddleware(authenticationHandler);
}
/**
* @public
* @static
* Creates a middleware chain with the given one
* @param {Middleware} middleware - The first middleware of the middleware chain
* @return A HTTPClient instance
*/
static createWithMiddleware(middleware: Middleware): HTTPClient {
return new HTTPClient(middleware);
}
}