Skip to content

Update the IRequestOptions interface to separate fetch options from ArcGIS REST JS options #1292

Description

@patrickarlt

For v5 we want to move most request and fetch options to separate requestOptions (option flags used in our internal request function) and fetchOptions (options passed to the internal call to fetch). The only things I would keep would at the top level would be authentication and params. This would mean our main IRequestOptions interface looks like this:

{
  params: Record<string, any>; // any additional params to append to the request
  authentication: IAuthenticationManager | string; // auth manager or access token
  requestOptions?: { // additional options for our intenal request method
    hideToken?: boolean; // put the token param in the header for GET requests
    suppressWarnings?: boolean // silence all internal console warnings from REST JS 
    injectRequestHeaders?: boolean; // add a `arcgisRestRequestHeaders` property that returns the request headers to resolve https://github.com/Esri/arcgis-rest-js/issues/1181
  };
  /** 
   * anything you can pass to the options for fetch 
   * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit 
   * REST JS may override or ignore these as it sees fit. REST JS
   * currently modifies the headers and credentials options.
   **/
  fetchOptions: RequestInit 

}

This would make it so that we can easily copy options around inside higher level methods where we make multiple internal calls to different endpoints like createApiKey() by using structuredClone()

There are a few other things to note:

  • This change should be backward compatible with the existing IRequestOptions so the new interface above should be added to it. Existing properties should all become optional and log a warning that they are deprecated when used.
  • The only option that we are going to outright remove is rawResponse. Instead we should export a new rawRequest() method which will simply perform the request and return the Response object.
  • There is no more f param on request() which will now only produce JSON. If you need a non-JSON response you can use rawRequest() and process the data yourself which would be the case for things like Feature layer queries as PBF etc...
    Finally it is OK if we override some of the users fetchOptions if we need too. We just need to document around this. For example we currently modify various headers, the credentials options etc... because we need too but users should be able to set custom headers, abort signal etc...

Format

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions