Hosted data services provide a way to store, manage, and access your own geographic data for maps. You can store data in ArcGIS as features, then access, query, and edit the data with the arcgis-rest-routing package.
Steps
- Import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer.
- Get the URL for the feature layer.
- Install and reference the
arcgis-rest-feature-serviceandarcgis-rest-requestpackages. - Set an access token to authenticate the request.
- Make a request to the service.
Access metadata
Accessing metadata allows you to retrieve detailed information about a feature layer, such its the owner, item ID, structure, fields, and settings.
Get layer metadata
Learn how to get layer metadata with the get method.
import { ApiKeyManager } from "@esri/arcgis-rest-request";
import { getService } from "@esri/arcgis-rest-feature-service";
const accessToken = "YOUR_ACCESS_TOKEN";
const authentication = ApiKeyManager.fromKey(accessToken);
getService("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_Styled/FeatureServer/0", {
authentication
}).then((response) => {
console.log(JSON.stringify(response, null, 2));
});Query features
Querying features enables you to request specific records from a feature service based on attribute criteria (SQL) or spatial relationships.
Query a feature layer
Learn how to perform an SQL query against a feature layer with the query method.
import { ApiKeyManager } from "@esri/arcgis-rest-request";
import { queryFeatures } from "@esri/arcgis-rest-feature-service";
const accessToken = "YOUR_ACCESS_TOKEN";
const authentication = ApiKeyManager.fromKey(accessToken);
queryFeatures({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/LA_County_Parcels/FeatureServer/0",
where: "UseType = 'Residential'",
resultRecordCount: 1,
authentication
}).then((response) => {
console.log(JSON.stringify(response, null, 2));
});Edit features
Editing features allows you to modify the content of a feature layer by adding new records, updating existing ones, or removing outdated data.
Edit feature data
Learn how to add, update, and delete features from a feature layer using the add, update, and delete methods.
import { ApiKeyManager } from "@esri/arcgis-rest-request";
import { addFeatures, updateFeatures, deleteFeatures } from "@esri/arcgis-rest-feature-service";
const accessToken = "YOUR_ACCESS_TOKEN";
const authentication = ApiKeyManager.fromKey(accessToken);
const featureServiceLayerUrl = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/my_points/FeatureServer/0";
const featureToAdd = {
attributes: {
id: 101,
name: "editing test",
rating: "2"
},
geometry: {
x: -118.807,
y: 34.002,
spatialReference: {
wkid: 4326