Skip to content

Commit 9617742

Browse files
Merge pull request #105 from microsoftgraph/Passing-Options-For-Fetch
Passing options for fetch
2 parents d723d95 + 46566cc commit 9617742

11 files changed

+579
-302
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ You can pass in additional request headers, either individually or in a dictiona
247247

248248
````
249249

250+
### .option() and .options()
251+
You can pass in additional request options, either individually or in a dictionay. Options can be [node specific](https://github.com/bitinn/node-fetch#options) or [from fetch standard](https://fetch.spec.whatwg.org/#requestinit)
252+
```js
253+
.option("someOptionName", "someOptionValue")
254+
// or
255+
.options({"someOptionName":"someOptionValue"})
256+
```
257+
250258
### .responseType()
251259
To set a custom response type, use the `.responseType(<ResponseType>)` method. Refer [ResponseType.ts](./src/ResponseType.ts) for available options.
252260
````js

lib/graph-js-sdk-core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/graph-js-sdk-web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/GraphRequest.d.ts

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import { Promise } from 'es6-promise';
22
import 'isomorphic-fetch';
3-
import { Options, URLComponents, GraphRequestCallback } from "./common";
3+
import { Options, URLComponents, GraphRequestCallback, FetchOptions } from "./common";
44
export declare class GraphRequest {
55
config: Options;
66
urlComponents: URLComponents;
7+
_options: FetchOptions;
78
_headers: {
8-
[key: string]: string | number;
9+
[key: string]: string;
910
};
1011
_responseType: string;
1112
constructor(config: Options, path: string);
1213
header(headerKey: string, headerValue: string): this;
1314
headers(headers: {
1415
[key: string]: string | number;
1516
}): this;
17+
option(key: string, value: any): this;
18+
options(options: {
19+
[key: string]: any;
20+
}): this;
1621
parsePath(rawPath: string): void;
1722
private urlJoin;
1823
buildFullUrl(): string;
@@ -28,21 +33,57 @@ export declare class GraphRequest {
2833
responseType(responseType: string): GraphRequest;
2934
private addCsvQueryParamater;
3035
delete(callback?: GraphRequestCallback): Promise<any>;
36+
/**
37+
* Alias for delete call
38+
*/
39+
del(callback?: GraphRequestCallback): Promise<any>;
3140
patch(content: any, callback?: GraphRequestCallback): Promise<any>;
3241
post(content: any, callback?: GraphRequestCallback): Promise<any>;
33-
put(content: any, callback?: GraphRequestCallback): Promise<any>;
42+
/**
43+
* Alias for Post call
44+
*/
3445
create(content: any, callback?: GraphRequestCallback): Promise<any>;
46+
put(content: any, callback?: GraphRequestCallback): Promise<any>;
47+
/**
48+
* Alias for update call
49+
*/
3550
update(content: any, callback?: GraphRequestCallback): Promise<any>;
36-
del(callback?: GraphRequestCallback): Promise<any>;
3751
get(callback?: GraphRequestCallback): Promise<any>;
52+
getStream(callback: GraphRequestCallback): Promise<any>;
53+
putStream(stream: any, callback: GraphRequestCallback): Promise<any>;
54+
/**
55+
* @private
56+
* Sends request and routes response to the callback or resolves to promise
57+
* @param {RequestInfo} request - The Request object or url string value
58+
* @param {FetchOptions} options - The options for the fetch api request
59+
* @param {GraphRequestCallback} callback - The callback that needs to be called on response
60+
* @return The promise in case if the callback param is empty
61+
*/
62+
private sendRequestAndRouteResponse;
63+
/**
64+
* @private
65+
* Gets the Promise that will resolve or reject with fetch api request
66+
* @param {RequestInfo} request - The Request object or url string value
67+
* @param {FetchOptions} options - The options for the fetch api request
68+
* @return The Promise that resolves with Response
69+
*/
3870
private routeResponseToPromise;
39-
private handleFetch;
71+
/**
72+
* @private
73+
* Makes request to the service by getting auth token from the auth provider
74+
* @param {RequestInfo} request - The Request object or url string value
75+
* @param {FetchOptions} options - The options for the fetch api request
76+
* @param {GraphRequestCallback} callback - The callback function
77+
*/
4078
private routeResponseToCallback;
41-
private sendRequestAndRouteResponse;
42-
getStream(callback: GraphRequestCallback): void;
43-
putStream(stream: any, callback: GraphRequestCallback): void;
44-
private getDefaultRequestHeaders;
45-
private configureRequest;
79+
/**
80+
* @private
81+
* Customizes the fetch options with the Auth token, SDKVersion header and customization applied via init, .header, .headers, .option, .options etc
82+
* @param {FetchOptions} options - The options for the fetch api request
83+
* @param {string} accessToken - The access token value
84+
* @return The fetch options with customization
85+
*/
86+
private configureRequestOptions;
4687
query(queryDictionaryOrString: string | {
4788
[key: string]: string | number;
4889
}): GraphRequest;

0 commit comments

Comments
 (0)