-
Notifications
You must be signed in to change notification settings - Fork 126
Introduce rawRequest() to replace rawResponse
#1317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
adbf710
290c292
bfb6539
ecf1c25
71eb068
ef0e0c5
60988fc
224e2b6
bd4812c
c6358f0
0fa2486
6197005
35d84fb
0baa47e
43e9f61
bf96460
dfb644b
6ca8013
1602de6
3974367
825536f
1ffaca5
141b65f
d1675a5
7f70ec6
e37a060
18e4da4
d5529a1
ca6ce04
af87f91
d4470a0
6c3ab3f
f6612a6
f634a0c
83eee25
c4c714b
0c6c675
92bb7a0
bea9adf
2bd2aa3
a362469
b2fccda
940990a
436dca5
2d0f684
dd42707
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| --- | ||
| "@esri/arcgis-rest-developer-credentials": major | ||
| "@esri/arcgis-rest-basemap-sessions": major | ||
| "@esri/arcgis-rest-feature-service": major | ||
| "@esri/arcgis-rest-demographics": major | ||
| "@esri/arcgis-rest-elevation": major | ||
| "@esri/arcgis-rest-geocoding": major | ||
| "@esri/arcgis-rest-request": major | ||
| "@esri/arcgis-rest-routing": major | ||
| "@esri/arcgis-rest-places": major | ||
| "@esri/arcgis-rest-portal": major | ||
| "@esri/arcgis-rest-auth": major | ||
| --- | ||
|
|
||
| This release changes how HTTP responses are accessed and redefines top-level request options. | ||
|
|
||
| ## Summary | ||
|
|
||
| This release introduces rawRequest() for direct HTTP response access and removes legacy request option patterns. | ||
|
|
||
| - `request()` returns JSON only. Non-JSON `f` values are coerced to `json` with a warning. | ||
| - `rawResponse` is no longer supported. Use `rawRequest()` instead. | ||
| - `maxUrlLength` is no longer supported. Use requestFlags.ignoreMaxUrlLength with GET requests to avoid REST JS coercing the request to POST for large URLs. | ||
|
|
||
| ## Breaking changes | ||
|
|
||
| - `request()` now only supports JSON payload handling by coercing `f=json`. | ||
|
|
||
| - If you pass `params.f` values like `text` or `html` to `request()`, the value is coerced to `json` and a warning is emitted. | ||
| - Use `rawRequest()` when you need custom response formats or direct access to the native Response. | ||
|
|
||
| - `rawResponse` as an `IRequestOptions` property is no longer supported for `request()`. | ||
|
|
||
| - Previous pattern: `request(url, { rawResponse: true, ... })` | ||
| - New pattern: `rawRequest(url, options)` | ||
|
|
||
| - `maxUrlLength` as an `IRequestOptions` property is no longer supported. | ||
| - Previous pattern: { maxUrlLength: 3000 } | ||
| - New pattern: { requestFlags: { ignoreMaxUrlLength: true } } | ||
|
|
||
| ## Why these changes were made | ||
|
|
||
| - Improve options handling and remove legacy properties. | ||
| - Make generic return types feasible. | ||
| - Contain HTTP-related fetch options and ArcGIS request flags within their own respective objects for a clearer API surface. | ||
|
|
||
| ## Migration guide | ||
|
|
||
| 1. Replace request(..., { rawResponse: true, ...options }) with rawRequest(..., options). | ||
|
|
||
| ```ts | ||
| // Before | ||
| const response = await request(url, { | ||
| rawResponse: true, | ||
| params: { f: "pbf" } | ||
| }); | ||
| const bytes = await response.arrayBuffer(); | ||
|
|
||
| // After | ||
| const response = await rawRequest(url, { params: { f: "pbf" } }); | ||
| const bytes = await response.arrayBuffer(); | ||
| ``` | ||
|
|
||
| 2. If you need text/html/blob/pbf from an endpoint, switch from request() to rawRequest(). | ||
|
|
||
| ```ts | ||
| // Before | ||
| const text = await request(url, { params: { f: "html" } }); | ||
|
|
||
| // After | ||
| const response = await rawRequest(url, { params: { f: "html" } }); | ||
| const text = await response.text(); | ||
| ``` | ||
|
|
||
| 3. Move top-level maxUrlLength usage to requestFlags.ignoreMaxUrlLength. | ||
|
|
||
| Before, you could specify a GET request, and it would return so long as the max URL length was < 2000 or < the user-specified `maxUrlLength`. | ||
| Now, if the max URL length surpasses 2000, `request()` will change request method from GET to POST unless the user specifies `ignoreMaxUrlLength` true in `requestFlags.ignoreMaxUrlLength`. | ||
|
|
||
| ```ts | ||
| // Before | ||
| await request(url, { httpMethod: "GET", maxUrlLength: 5000 }); | ||
|
|
||
| // After | ||
| await request(url, { | ||
| fetchOptions: { method: "GET" }, | ||
| requestFlags: { ignoreMaxUrlLength: true } | ||
| }); | ||
| ``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ import { | |
| IExtent, | ||
| ArcGISRequestError, | ||
| ArcGISAuthError, | ||
| IRequestOptions | ||
| IRequestOptions, | ||
| rawRequest | ||
| } from "@esri/arcgis-rest-request"; | ||
|
|
||
| import { | ||
|
|
@@ -77,9 +78,7 @@ export interface IQueryFeaturesOptions extends ISharedQueryOptions { | |
| sqlFormat?: "none" | "standard" | "native"; | ||
| returnExceededLimitFeatures?: boolean; | ||
| /** | ||
| * Response format. Defaults to "json" | ||
| * NOTE: for "pbf" you must also supply `rawResponse: true` | ||
| * and parse the response yourself using `response.arrayBuffer()` | ||
| * Response format. Defaults to "json". | ||
| */ | ||
| f?: "json" | "geojson" | "pbf" | "pbf-as-geojson" | "pbf-as-arcgis"; | ||
| /** | ||
|
|
@@ -134,7 +133,7 @@ export interface IQueryAllFeaturesOptions extends ISharedQueryOptions { | |
| returnExceededLimitFeatures?: true; | ||
| /** | ||
| * Response format. Defaults to "json" | ||
| * NOTE: for "pbf" you must also supply `rawResponse: true` | ||
| * NOTE: for "pbf" you must use the method `rawRequest()` | ||
| * and parse the response yourself using `response.arrayBuffer()` | ||
| */ | ||
| f?: "json" | "geojson" | "pbf-as-geojson" | "pbf-as-arcgis"; | ||
|
|
@@ -188,17 +187,16 @@ export function queryPbfAsGeoJSONOrArcGIS( | |
| // default pbf request to EPSG:4326 if requesting pbf-as-geojson to satisfy geojson crs standard | ||
| const geoJSONSpatialReference = | ||
| queryOptions.params.f === "pbf-as-geojson" ? { outSR: "4326" } : {}; | ||
| // query with f=pbf and rawResponse:true on behalf of the user to fetch metadata with the pbf response | ||
| // query with f=pbf and rawRequest on behalf of the user to fetch metadata with the pbf response | ||
| const customOptions = { | ||
| ...queryOptions, | ||
| params: { | ||
| ...queryOptions.params, | ||
| ...geoJSONSpatialReference, | ||
| f: "pbf" | ||
| } as any, | ||
| rawResponse: true | ||
| } as any | ||
| }; | ||
| return request(`${cleanUrl(url)}/query`, customOptions).then( | ||
| return rawRequest(`${cleanUrl(url)}/query`, customOptions).then( | ||
| async (response: any) => { | ||
| // if pbf request to service returns a json format, there is an error | ||
| if (response.headers.get("content-type")?.includes("application/json")) { | ||
|
|
@@ -270,24 +268,22 @@ export function queryPbfAsGeoJSONOrArcGIS( | |
| * ``` | ||
| * | ||
| * @param requestOptions - Options for the request | ||
| * @returns A Promise that will resolve with the feature or the [response](https://developer.mozilla.org/en-US/docs/Web/API/Response) itself if `rawResponse: true` was passed in. | ||
| * @returns A Promise that resolves with the feature by default, or with the native Response when `rawResponse` is `true`. | ||
| */ | ||
| export function getFeature( | ||
| requestOptions: IGetFeatureOptions | ||
|
dixonyant marked this conversation as resolved.
|
||
| ): Promise<IFeature> { | ||
| ): Promise<IFeature | Response> { | ||
| const url = `${cleanUrl(requestOptions.url)}/${requestOptions.id}`; | ||
|
|
||
| // default to a GET request | ||
| const options: IGetFeatureOptions = { | ||
| ...{ httpMethod: "GET" }, | ||
| ...requestOptions | ||
| }; | ||
|
dixonyant marked this conversation as resolved.
|
||
| return request(url, options).then((response: any) => { | ||
| if (options.rawResponse) { | ||
| return response; | ||
| } | ||
| return response.feature; | ||
| }); | ||
| if (options.rawResponse) { | ||
| return rawRequest(url, options); | ||
| } | ||
| return request(url, options).then((response: any) => response.feature); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -365,6 +361,11 @@ export function queryFeatures( | |
| queryOptions.params?.f === "pbf-as-arcgis" | ||
| ) { | ||
| return queryPbfAsGeoJSONOrArcGIS(requestOptions.url, queryOptions); | ||
| } else if (queryOptions.params?.f === "pbf") { | ||
| return rawRequest( | ||
| `${cleanUrl(requestOptions.url)}/query`, | ||
| queryOptions | ||
| ) as Promise<any>; | ||
|
Comment on lines
+364
to
+368
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dixonyant this also seems off. The goal is that all methods should return JSON by default and this breaks the pattern by returning
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it is off. This in-between behavior shouldn't even see the light of day since the follow-up PR is going to be all the removing of rawRequest calls from all functions that should be only returning JSON. They either get a replacement rawFunction call after v5 or with v5. Just the purpose of this PR is to replace the guts of all calls to |
||
| } | ||
|
dixonyant marked this conversation as resolved.
|
||
| return request(`${cleanUrl(requestOptions.url)}/query`, queryOptions); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.