0% found this document useful (0 votes)
11 views

13.7 - Using Application Programming Interfaces

This document discusses APIs, specifically focusing on a geocoding API based on OpenStreetMap data, which requires an account for access but offers a free usage level. It also describes a proxy server that allows access to the Geoapify data without authentication, while implementing rate limits. Additionally, it covers the concepts of Service Oriented Architecture, web services, and serialization formats like XML and JSON.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

13.7 - Using Application Programming Interfaces

This document discusses APIs, specifically focusing on a geocoding API based on OpenStreetMap data, which requires an account for access but offers a free usage level. It also describes a proxy server that allows access to the Geoapify data without authentication, while implementing rate limits. Additionally, it covers the concepts of Service Oriented Architecture, web services, and serialization formats like XML and JSON.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

PYTHON FOR

Web Services – Part 7 EVERYBODY

APIs

http://en.wikipedia.org/wiki/Web_services
PYTHON FOR
Web Services – Part 7 EVERYBODY

There Are Many APIs


• There are organizations that put up public APIs and sell
access to those APIs
• We will explore a geocoding API based on the
OpenStreetMap data
• You need an account to access this API
• There is a free level of requests
• You pay above that rate of usage
https://www.geoapify.com/
PYTHON FOR
Web Services – Part 7 EVERYBODY

https://www.geoapify.com/
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY
PYTHON FOR
Web Services – Part 7 EVERYBODY

An API Proxy
• To avoid making you get an account, I have a well-hidden
web server that acts as a proxy for the Geoapify data
• This proxy does not require a password – but it does have
rate limits and is heavily cached using an edge-caching
service for performance

Your code cloudflare py4e-data Geoapi


PYTHON FOR
Web Services – Part 7 EVERYBODY

{ http://py4e-data.dr-chuck.net/opengeo?q=Ann+Arbor%2C+MI
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"datasource": {
"sourcename": "openstreetmap",
"attribution": "© OpenStreetMap contributors",
"license": "Open Database License",
"url": "https://www.openstreetmap.org/copyright"
},
"country": "United States",
Note, for this course, we
"country_code": "us",
operate through a proxy of the
"state": "Michigan",
geoapi data to avoid rate
"county": "Washtenaw County",
limitation and authentication.
"city": "Ann Arbor",
"lon": -83.7312291,
"lat": 42.2681569,
"state_code": "MI", opengeo.py
"result_type": "city",
"formatted": "Ann Arbor, MI, United States of America",
PYTHON FOR
Web Services – Part 7 EVERYBODY

import urllib.request, urllib.parse


import http, json, ssl

serviceurl = 'https://py4e-data.dr-chuck.net/opengeo?'
Enter location: Ann Arbor, MI
while True: Retrieving https://py4e-data.
address = input('Enter location: ')
if len(address) < 1: break
dr-chuck.net/opengeo?q=Ann+Arbor%2C+MI
Retrieved 1319 characters {"type":"FeatureColl
address = address.strip() lat 42.2681569 lon -83.7312291
parms = dict()
parms['q'] = address Ann Arbor, MI, United States of America
url = serviceurl + urllib.parse.urlencode(parms)

print('Retrieving', url)
uh = urllib.request.urlopen(url, context=ctx)
data = uh.read().decode()
print('Retrieved', len(data), 'characters', data[:20].replace('\n', ' '))

js = json.loads(data)

lat = js['features'][0]['properties']['lat']
lon = js['features'][0]['properties']['lon'] opengeo.py
print('lat', lat, 'lon', lon)
location = js['features'][0]['properties']['formatted']
print(location)
PYTHON FOR
Web Services – Part 7 EVERYBODY

Summary
• Service Oriented Architecture - allows an application to be
broken into parts and distributed across a network

• An Application Program Interface (API) is a contract for


interaction

• Web Services provide infrastructure for applications


cooperating (an API) over a network - SOAP and REST are two
styles of web services

• XML and JSON are serialization formats


PYTHON FOR
Web Services – Part 7 EVERYBODY

Acknowledgements / Contributions
These slides are Copyright 2010- Charles R. Severance
...
(www.dr-chuck.com) of the University of Michigan School of
Information and open.umich.edu and made available under a
Creative Commons Attribution 4.0 License. Please maintain this
last slide in all copies of the document to comply with the
attribution requirements of the license. If you make a change,
feel free to add your name and organization to the list of
contributors on this page as you republish the materials.

Initial Development: Charles Severance, University of Michigan


School of Information

… Insert new Contributors here

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy