![Page 1: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/1.jpg)
John Foster
ArcGIS REST APIGetting Started
![Page 2: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/2.jpg)
ArcGIS REST API
• Who is this talk talking to?• What are we going to cover in this talk?• This is intro + getting started
• Also check out: ArcGIS REST API: Advanced Techniques- Wed 2/12 1:30 PM 102B
![Page 3: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/3.jpg)
• ArcGIS Online, MapViewer• Storymaps, Operations Dashboard, Insights• SDKs: JavaScript, Runtime, Python• ArcGIS Hub• Developer’s website• ArcGIS Pro• …and many others
Who is using REST?
Have portal, will REST
![Page 4: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/4.jpg)
What is REST?
• REST == REpresentational State Transfer
• For distributed hypermedia systems (HTTP/HTTPS)
• First presented by Roy Fielding in 2000 • See https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
![Page 5: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/5.jpg)
• URI “endpoint”• operations, or methods:
- GET- POST- PUT- PATCH- DELETE
• parameters• headers• response status code• response
HTTP/S protocol
https://developer.mozilla.org/en-US/docs/Web/HTTP
![Page 6: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/6.jpg)
REST in action
• Let’s look at some REST
![Page 7: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/7.jpg)
Examplehttps://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?f=json&SingleLine=Washington%20Convention%20Center%2C%20Washington%20DC&category=POI&outFields=*&forStorage=false
![Page 8: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/8.jpg)
ExampleEndpoint (URI):https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates
Parameters:f=jsonSingleLine=Washington%20Convention%20Center%2C%20Washington%20DCcategory=POIoutFields=*forStorage=false
![Page 9: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/9.jpg)
REST in action
• Let’s try a geocode
![Page 10: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/10.jpg)
REST in action
• Let’s try a geocode – type this into a browser:
https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?f=json&SingleLine=Washington%20Convention%20Center%2C%20Washington%20DC&category=POI&outFields=*&forStorage=false
![Page 11: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/11.jpg)
REST in action
• Let’s try a geocode – create an HTML page:
<form method="post"action="https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"><label for="SingleLine">Point of interest:</label><input type="text"
name="SingleLine"><input type="hidden" name="category" value="POI"><input type="hidden" name="outFields" value="*"><input type="hidden" name="f" value="json"><input type="submit" value="Post">
</form>
![Page 12: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/12.jpg)
REST in action
• Let’s try a geocode – create a shell script:
#!/bin/bash##################################################protocol="https://"host="geocode.arcgis.com"endpoint="/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"url="${protocol}${host}${endpoint}"parameters="f=json&category=POI&outFields=*&SingleLine=${1}"echo "${url}?${parameters}"curl "${url}?${parameters}"
![Page 13: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/13.jpg)
REST in action
• Let’s try a feature service – type this on a command line:
curl -G "https://services8.arcgis.com/LLNIdHmmdjO2qQ5q/arcgis/rest/admin/services/ufo_sightings_de/FeatureServer?f=json"
![Page 14: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/14.jpg)
Get a token
• Developer dashboard: https://developers.arcgis.com/dashboard
• By script: https://developers.arcgis.com/labs/rest/get-an-access-token/
![Page 15: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/15.jpg)
REST in action
• Let’s try a feature service – type this on a command line:
curl -G "https://services8.arcgis.com/LLNIdHmmdjO2qQ5q/arcgis/rest/admin/services/ufo_sightings_de/FeatureServer?f=json&token="
![Page 16: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/16.jpg)
Pitfalls!• cURL only gets you so far• Very inflexible• Not handling parameters, auth, errors• Writing lots of (bad) code
![Page 17: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/17.jpg)
Postman• https://www.getpostman.com/downloads/
![Page 18: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/18.jpg)
Postman• ArcGIS tutorials:
https://developers.arcgis.com/labs/browse/?product=rest-api&topic=any
• ArcGIS REST API: https://github.com/esri-es/ArcGIS-REST-API
![Page 19: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/19.jpg)
Postman• https://www.getpostman.com/downloads/• Great for managing collections of endpoints• Great for testing endpoints, API development• Not great for building an app
![Page 20: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/20.jpg)
JavaScript• fairly easy to encode REST API calls with JavaScript• XMLHttpRequest• fetch• jquery• 3rd party libs, npm
![Page 21: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/21.jpg)
JavaScript• XMLHttpRequest• https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
![Page 22: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/22.jpg)
JavaScript// construct the url yourself and don't forget to tack on f=jsonconst url = "https://www.arcgis.com/sharing/rest/community/users/dmfenton";url += "?f=json";var xhr = new XMLHttpRequest();xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {// make sure JSON response doesn’t indicate an errorif (!xhr.responseText.error) {xhr.responseText; //{firstName:"Daniel",description:”I’m a dev"...}
}}
}xhr.open('GET', url, true);xhr.send(null);
![Page 23: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/23.jpg)
JavaScript• fetch• https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
![Page 24: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/24.jpg)
JavaScriptconst url = "https://www.arcgis.com/sharing/rest/community/users/dmfenton";fetch(url, {method: "POST", // set the request typeheaders: {"Content-Type": "application/x-www-form-urlencoded" // append the right header
},// concat and encode parameters, append f=jsonbody: encodeURIComponent("f=json")
}).then(response => {if (response.ok) { return response.json() } // dig out the json
}).then(response => {// trap for errors inside a 200 responseif (!response.error) { return response; }})
![Page 25: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/25.jpg)
Many issues handling all this on your own:
• Lots of boiler plate code 🤕🤕• What are all the error codes? 🤷🤷🤷♀
• How do you handle authentication? 🤷🤷🤷♀
• How are dates supposed to be encoded? 🤷🤷🤷♀
• Proper encoding for objects? 🤷🤷🤷♀
• How do you manage tokens for federated servers? 🤷🤷🤷♀
• Refreshing authentication when necessary? 🤕🤕
Managing complexity
![Page 26: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/26.jpg)
Is there a better way?
![Page 27: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/27.jpg)
ArcGIS REST JS
@esri/arcgis-rest-js helps you
talk to ArcGIS Online and Enterprise
from modern browsers and Node.js.
![Page 28: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/28.jpg)
ArcGIS REST JS
kind of analogous to ArcGIS API for Python
much different than the ArcGIS API for JavaScript
different goals and use cases
![Page 29: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/29.jpg)
ArcGIS REST JS
Open source on GitHub
Code 🎛🎛 https://github.com/Esri/arcgis-rest-js
Doc 📚📚 https://esri.github.io/arcgis-rest-js
![Page 30: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/30.jpg)
ArcGIS REST JS simplifiesimport { request } from "@esri/arcgis-rest-request";
request(url).then(response) // {firstName:"Daniel",description:"open source geodev" ... }.catch((error => {if(err.name === "ArcGISAuthError"){// handle and auth error
} else {// handle a regular error
}})
![Page 31: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/31.jpg)
• Knows how to converse with ArcGIS portals- Authentication, token management- f=json - parameter encoding- uses FormData when required- clear and informative error handling
• but, not for- map and layer rendering- client-side analysis
ArcGIS REST JS value adds
![Page 32: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/32.jpg)
Pass-through parameters// url, IRequestOptionsrequest(url, {
params: { // anything you want to pass to the endpointfoo: true,bar: "baz",attachment: File(),num: 999,when: Date().now() // etc.
},// httpMethod: "GET",// authentication// portal,// headers,// fetch})
![Page 33: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/33.jpg)
Request is the foundationimport { geocode } from "@esri/arcgis-rest-geocoder";
// assumes you want to use ArcGIS Onlinegeocode("Washington Convention Center, Washington DC").then(response) // { ... candidates: [] }
// IRequestOptions is still availablegeocode("Washington Convention Center, Washington DC", {params: {
category: "POI",outFields: "*"
},authentication})
![Page 34: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/34.jpg)
ArcGIS REST JS Goals• Ease the use of ArcGIS REST endpoints• Node.js and (modern) browsers• a la carte services• framework agnostic• align with JS ecosystem
![Page 35: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/35.jpg)
ArcGIS REST JS Disclaimer• not a product, no roadmap• not a product, no official support• work in progress, compare https://developers.arcgis.com/rest/• open source, contributions welcome!
![Page 36: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/36.jpg)
Demo
![Page 37: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/37.jpg)
Location services- Geocode- Routing- Demographics- Analysis- Elevation- Packaging
What services are available?
ArcGIS Online and Enterprise- Users- Groups- Items
ArcGIS Enterprise- Server- Portal- Notebooks- Extensions
https://developers.arcgis.com/rest/
![Page 38: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/38.jpg)
Resources• ArcGIS REST API https://developers.arcgis.com/rest/
• arcgis-rest-js code https://github.com/Esri/arcgis-rest-js
• arcgis-rest-js documentation https://esri.github.io/arcgis-rest-js
• Hosted Feature Service resource https://github.com/esri-es/ArcGIS-REST-
API/tree/master/HostedFeatureServices
• HTTP: https://developer.mozilla.org/en-US/docs/Web/HTTP
![Page 39: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/39.jpg)
Resources• ArcGIS REST API https://developers.arcgis.com/rest/
• arcgis-rest-js code https://github.com/Esri/arcgis-rest-js
• arcgis-rest-js documentation https://esri.github.io/arcgis-rest-js
• Hosted Feature Service resource https://github.com/esri-es/ArcGIS-REST-
API/tree/master/HostedFeatureServices
• HTTP: https://developer.mozilla.org/en-US/docs/Web/HTTP
• cURL: https://curl.haxx.se/
![Page 40: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/40.jpg)
Questions?
![Page 41: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/41.jpg)
Print Your Certificate of Attendance
Print Stations Located in 150 Concourse Lobby
Tuesday12:30 pm – 6:30 pmExpoHall B
5:15 pm – 6:30 pmExpo SocialHall B
Wednesday10:45 am – 5:15 pmExpoHall B
6:30 pm – 9:30 pmNetworking ReceptionSmithsonian National Museumof Natural History
![Page 42: ArcGIS REST API Getting StartedThis is intro + getting started • Also check out: ArcGIS REST API: Advanced Techniques-Wed 2/12 1:30 PM 102B Sample the audience to understand who](https://reader030.vdocument.in/reader030/viewer/2022013023/5faced21175d3d174e12c29d/html5/thumbnails/42.jpg)
Download the EsriEvents app and find
your event
Select the session you attended
Scroll down to “Survey”
Log in to access the survey
Complete the survey and select “Submit”
Please Share Your Feedback in the App