Blockchain Nanodegree 预修知识之三:RESTful APIs(2)

Lesson 2: Accessing Published APIs

HTTP

HTTP Requests

header:
  • request line (HTTP verb, URI, HTTP version number)
  • optional request headers
blank line
body (optional)

Sending API Requests with Postman and Curl

Check out the official cURL documentation and this blog post for getting started with cURL.

Check out the Postman Documentation as well.

Google Geocoding API

import httplib2
import json

def getGeocodeLocation(inputString):
    google_api_key = "PASTE_YOUR_KEY_HERE"
    locationString = inputString.replace(" ", "+")
    url = ('https://maps.googleapis.com/maps/api/ \
    geocode/json?address=%s&key=%s'% (locationString, 
    google_api_key))
    h = httplib2.Http()
    response, content = h.request(url, 'GET')
    result = json.loads(content)
    #print response
    latitude = result['results'][0]['g''eometry']['location']['lat']
    longitude = result['results'][0]['geometry']['location']['lng']
    return (latitude, longitude)

API Mashup

findARestaurant(mealType, location)

  1. Geocode the location
  2. Search for restaurants
  3. Parse response and return one restaurant

Download the starter code for this exercise.

View the solution code for this exercise.

Some Interesting APIs to Explore

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值