How to use @esri/arcgis-rest-request - 10 common examples

To help you get started, we’ve selected a few @esri/arcgis-rest-request examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Esri / arcgis-rest-js / packages / arcgis-rest-portal / src / util / SearchQueryBuilder.ts View on Github external
private addModifier(modifier: string) {
    if (this.currentModifer) {
      warn(
        // prettier-ignore
        `You have called \`${this.currentModifer}()\` after \`${modifier}()\`. Your current query was not modified.`
      );
      return this;
    }

    this.commit();

    if (this.q === "") {
      warn(
        `You have called \`${modifier}()\` without calling another method to modify your query first. Try calling \`match()\` first.`
      );
      return this;
    }

    this.currentModifer = modifier;
github Esri / arcgis-rest-js / packages / arcgis-rest-portal / src / util / SearchQueryBuilder.ts View on Github external
private addModifier(modifier: string) {
    if (this.currentModifer) {
      warn(
        // prettier-ignore
        `You have called \`${this.currentModifer}()\` after \`${modifier}()\`. Your current query was not modified.`
      );
      return this;
    }

    this.commit();

    if (this.q === "") {
      warn(
        `You have called \`${modifier}()\` without calling another method to modify your query first. Try calling \`match()\` first.`
      );
      return this;
    }

    this.currentModifer = modifier;
    this.q += ` ${modifier.toUpperCase()} `;
    return this;
  }
github Esri / arcgis-rest-js / packages / arcgis-rest-portal / src / util / SearchQueryBuilder.ts View on Github external
public in(this: SearchQueryBuilder, field?: string) {
    const fn = `\`in(${field ? `"${field}"` : ""})\``;

    if (!this.hasRange && !this.hasTerms) {
      warn(
        // prettier-ignore
        `${fn} was called with no call to \`match(...)\` or \`from(...)\`/\`to(...)\`. Your query was not modified.`
      );
      return this;
    }

    if (field && field !== "*") {
      this.q += `${field}: `;
    }

    return this.commit();
  }
github Esri / solution.js / src / itemFactory.js View on Github external
.then(resolve);
                    }, function () {
                        // If it fails, try URL for group base section
                        groups.getGroup(id, requestOptions)
                            .then(function (itemSection) {
                            var newGroup = new group_1.Group(itemSection);
                            newGroup.init(requestOptions)
                                .then(resolve);
                        }, function () {
                            var error = new arcgis_rest_request_1.ArcGISRequestError("Item or group does not exist or is inaccessible.");
                            reject(error);
                        });
                    });
                }
                catch (notUsed) {
                    var error = new arcgis_rest_request_1.ArcGISRequestError("Item or group does not exist or is inaccessible.");
                    reject(error);
                }
            });
        };
github Esri / arcgis-rest-js / packages / arcgis-rest-items / src / items.ts View on Github external
export function addItemData(
  requestOptions: IItemDataAddRequestOptions
): Promise {
  const owner = determineOwner(requestOptions);

  const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
    requestOptions.id
  }/update`;

  // Portal API requires that the 'data' be POSTed in a `file` form field.
  requestOptions.params = {
    file: requestOptions.data,
    ...requestOptions.params
  };

  return request(url, requestOptions);
}
/**
github Esri / arcgis-rest-js / packages / arcgis-rest-portal / src / util / generic-search.ts View on Github external
switch (searchType) {
    case "item":
      path = "/search";
      break;
    case "group":
      path = "/community/groups";
      break;
    default:
      // "users"
      path = "/portals/self/users/search";
      break;
  }
  url = getPortalUrl(options) + path;

  // send the request
  return request(url, options).then(r => {
    if (r.nextStart && r.nextStart !== -1) {
      r.nextPage = function() {
        let newOptions: ISearchOptions;

        if (
          typeof search === "string" ||
          search instanceof SearchQueryBuilder
        ) {
          newOptions = {
            q: search,
            start: r.nextStart
          };
        } else {
          newOptions = search;
          newOptions.start = r.nextStart;
        }
github Esri / arcgis-rest-js / packages / arcgis-rest-auth / src / fetch-token.ts View on Github external
export function fetchToken(
  url: string,
  requestOptions: ITokenRequestOptions
): Promise {
  const options: IRequestOptions = requestOptions;
  // we generate a response, so we can't return the raw response
  options.rawResponse = false;

  return request(url, options).then((response: IFetchTokenRawResponse) => {
    const r: IFetchTokenResponse = {
      token: response.access_token,
      username: response.username,
      expires: new Date(
        // convert seconds in response to milliseconds and add the value to the current time to calculate a static expiration timestamp
        Date.now() + (response.expires_in * 1000 - 1000)
      ),
      ssl: response.ssl === true
    };
    if (response.refresh_token) {
      r.refreshToken = response.refresh_token;
    }

    return r;
  });
}
github Esri / arcgis-rest-js / packages / arcgis-rest-portal / src / sharing / access.ts View on Github external
// if the user wants to make the item private, it needs to be unshared from any/all groups as well
  if (requestOptions.access === "private") {
    requestOptions.params.groups = " ";
  }
  if (requestOptions.access === "org") {
    requestOptions.params.org = true;
  }
  // if sharing with everyone, share with the entire organization as well.
  if (requestOptions.access === "public") {
    // this is how the ArcGIS Online Home app sets public access
    // setting org = true instead of account = true will cancel out all sharing
    requestOptions.params.account = true;
    requestOptions.params.everyone = true;
  }
  return request(url, requestOptions);
}
github Esri / arcgis-rest-js / packages / arcgis-rest-items / src / items.ts View on Github external
if (typeof search === "string") {
    options.params.q = search;
  } else {
    options.params = search.searchForm;
    // mixin, giving user supplied requestOptions precedence
    options = {
      ...options,
      ...search
    };
  }

  // construct the search url
  const url = `${getPortalUrl(options)}/search`;

  // send the request
  return request(url, options);
}
github Esri / arcgis-rest-js / packages / arcgis-rest-feature-layer / src / getAttachments.ts View on Github external
export function getAttachments(
  requestOptions: IGetAttachmentsOptions
): Promise<{ attachmentInfos: IAttachmentInfo[] }> {
  const options: IGetAttachmentsOptions = {
    httpMethod: "GET",
    ...requestOptions
  };

  // pass through
  return request(
    `${cleanUrl(options.url)}/${options.featureId}/attachments`,
    options
  );
}