forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPClient.ts
More file actions
56 lines (50 loc) · 1.71 KB
/
Copy pathHTTPClient.ts
File metadata and controls
56 lines (50 loc) · 1.71 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
49
50
51
52
53
54
55
56
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module HTTPClient
*/
import { Context } from "./IContext";
import { FetchOptions } from "./IFetchRequest";
import { Middleware } from "./IMiddleware";
import { MiddlewareOptions } from "./IMiddlewareOptions";
/**
* @class
* Class representing HTTPClient
*/
export class HTTPClient {
/**
* @private
* A member holding first middleware of the middleware chain
*/
private middleware: Middleware;
/**
* @constructor
* Creates an instance of a HTTPClient
* @param {Middleware} middleware - The first middleware of the middleware chain
*/
constructor(middleware: Middleware) {
this.middleware = middleware;
}
/**
* @public
* @async
* To send the request through the middleware chain
* @param {RequestInfo} request - The request url string or the Request instance
* @param {FetchOptions} options - The options of a request
* @param {MiddlewareOptions} middlewareOptions - The options of a middleware chain
* @return A promise that resolves to the response
*/
public async sendRequest(request: RequestInfo, options: FetchOptions, middlewareOptions: MiddlewareOptions): Promise<any> {
let context: Context = {
request,
options,
middlewareOptions
};
await this.middleware.execute(context);
return context;
}
}