withOptions

Function

Allows you to wrap individual methods with a default set of request options. This is useful to avoid setting the same option more then once and allows for interacting and setting defaults in a functional manner.

import { withOptions } from "@esri/arcgis-rest-request";
import { queryFeatures } from '@esri/arcgis-rest-feature-layer';

const queryTrails = withOptions({
  url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0/"}, queryFeatures);

queryTrails({
  where: "ELEV_FT > 1000"
}).then(result);

const queryTrailsAsUser = withOptions({
  authentication: userSession
}, queryTrails);

queryTrailsAsUser({
  where: "TRL_NAME LIKE '%backbone%'"
}).then(result);
  • withOptions(defaultOptions: IRequestOptions, func: function(args: any[] | any) : any) : function(funcArgs: Parameters<function(args: any[] | any) : any>) : ReturnType<function(args: any[] | any) : any>

Parameters

Parameter Type Default Notes
defaultOptions Required IRequestOptions

The options to pass into to the func.

func Required function(args: any[] | any) : any

Any function that accepts anything extending IRequestOptions as its last parameter.

Returns

A copy of func with the defaultOptions passed in as defaults.

function(funcArgs: Parameters<function(args: any[] | any) : any>) : ReturnType<function(args: any[] | any) : any>

Function defined in packages/arcgis-rest-request/src/utils/with-options.ts:30