Skip to content

Commit

Permalink
feat: add support for streaming request response
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerjt committed Feb 14, 2019
1 parent 9b2b67f commit 893e647
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/arcgis-rest-request/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export interface IRequestOptions {
*/
httpMethod?: HTTPMethods;

/**
* The response should be a stream
*/
stream?: boolean;

/**
* The instance of `IAuthenticationManager` to use to authenticate this request.
*/
Expand Down Expand Up @@ -137,7 +142,7 @@ export function request(
);
}

const { httpMethod, authentication } = options;
const { httpMethod, authentication, stream } = options;

const params: IParams = {
...{ f: "json" },
Expand Down Expand Up @@ -215,6 +220,9 @@ export function request(
options
);
}
if (stream) {
return response.body;
}
switch (params.f) {
case "json":
return response.json();
Expand All @@ -230,7 +238,7 @@ export function request(
}
})
.then(data => {
if (params.f === "json" || params.f === "geojson") {
if ((params.f === "json" || params.f === "geojson") && !stream) {
return checkForErrors(data, url, params, options);
} else {
return data;
Expand Down

0 comments on commit 893e647

Please sign in to comment.