Key concepts
This document provides an overview of how to work with ArcGIS REST JS to build mapping applications. ArcGIS REST JS is library that contains a collection of packages that are framework agnostic. Implementing ArcGIS Rest JS packages allows you to:
- Simplify making requests to ArcGIS Online, ArcGIS Enterprise, and ArcGIS Platform location service REST APIs.
- Use CDN, NodeJS, or tree-shakeable ES modules.
- Work with popular module bundlers like: webpack, Rollup, and Parcel.
Packages
To make requests to services, you reference packages in the library in your application. These packages provide helpers that allow you to make low-level requests, authenticate users, query, geocode, route, and access demographic data.
@esri/arcgis-rest-request
: Undperins all other packages, supports low-level requests.@esri/arcgis-rest-auth
: Provides methods to authenticate named users and applications.@esri/arcgis-rest-feature-layer
: Provides functions to query and edit features in hosted feature layers.@esri/arcgis-rest-geocoding
: A geocoding wrapper for@esri/arcgis-rest-js
.@esri/arcgis-rest-routing
: A routing and directions wrapper for@esri/arcgis-rest-js
.@esri/arcgis-rest-demographics
: To access the GeoEnrichment service.
Referencing libraries
Here is an example of how to reference libraries using different frameworks.
Authentication
ArcGIS REST JS handles both API key and OAuth 2.0 methods of authentication. Visit Security and authentication to learn more about API keys and OAuth2.0 in the Mapping APIs and location services guide.
API key
If your application needs to access location services, use an API Key from your developer dashboard. When using an API key, make sure that it is properly scoped to the services you are accessing.
- Reference the library.
- Get an API key from your dashboard.
- Set the API key.
To learn more, go to the tutorials.
OAuth 2.0
When your app requires access to Esri secure user content or if you are distributing your app through ArcGIS Marketplace, you should implement OAuth 2.0 to obtain an ArcGIS identity.
The ArcGIS REST JS authentication package includes modules such as UserSession to authenticate users with their ArcGIS Online or ArcGIS Enterprise accounts. Other OAuth 2.0 calls you can use include generating and exchanging tokens.
- Reference the library.
- Go to your dashboard.
- Create or use an existing application.
- Get the client ID from your application.
- Set the client ID.
Working with location services
ArcGIS location services includes a number of services for geocoding, routing, demographic analysis, and spatial analysis. In ArcGIS REST JS, there are libraries for accessing each of the different services and functionality. To learn more, visit the tutorials.
The typical steps for accessing a service is to:
- Reference the appropriate libraries.
- Set the API key to authenticate the request.
- Define parameters to pass to the service.
- Call the service and handle the results.
Geocoding service
To learn more, go to the Search for an address tutorial.
Routing service
To learn more, go to the Find a route and directions tutorial.
Working with hosted feature layers
You can use ArcGIS REST JS to access your own data through services hosted in the ArcGIS Platform. To create hosted layers and services, you can import and publish data using data management tools. Once created, you can access the layers and services using ArcGIS REST JS.
- Import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer. See Import data as a feature layer.
- Get the URL for the feature layer. See Access feature layer data.
- Make a request to the service to access metadata.
Access hosted feature layer data
After your data is hosted, you can access the metadata with a URL.
To learn more, go to the Get layer metadata tutorial.
Query and edit hosted feature layer data
With the service URL from a published hosted feature layer, you can make different requests to the service using feature layer helpers to query and edit features.
Query
Use a SQL where clause or spatial queries to access subsets of data in a hosted feature layer.
To learn more, go to the Query a feature layer (SQL) tutorial.
Edit
Add, update, and delete features in a hosted feature layer.
To learn more, go to the Edit feature data tutorial.
Resources
Here are some useful resources to help create applications with ArcGIS REST JS and ArcGIS location services: