General Assembly

Advanced APIs

Wilson Espina

Review

What did we do last lesson?

Advanced APIs

Learning Objective

Learning Objectives

At the end of this class, you will be able to:

  • Request data from a web service.
  • Implement the geolocation API to request a location.
  • Use Postman to construct and test an API request.
  • Process a third-party API response and share location data on your website.
  • Search documentation needed to make and customise third-party API requests.

Advanced APIs

Agenda

  • Homework Review
  • Fetch (lesson 12)
  • Get oriented with Google Maps Platform & TFL API
  • Implement geolocation
  • Set up Postman
  • Create and send API call
  • Handle API response

Advanced APIs

Exit Ticket Questions

  1. Can we have more hands on exercises (rather than code alongs and slides)?
  2. Can you provide simple examples for abstract principles?

Advanced APIs

Homework Review

Advanced APIs

Classroom Resources

  • Pull changes from the wilson-espina/jsd-9-resources repo to your computer
  • In your editor, open the following folder: Documents/JSD/jsd-9-resources/12-advanced-apis
  • If you havenโ€™t already, sign up for a Postman account at https://getpostman.com, and optionally download the Postman app.

Asynchronous JavaScript

Fetch and Promises

Code along

Code Along

Open up: 00-fetch-codealong

Code Along

Advanced APIs

Advanced APIs

Advanced APIs

Building Our App

Bike app screenshot
Google maps api logo TFL logo

Advanced APIs

Building Our App - Steps

  1. Get userโ€™s location.
  2. Render a Google map.
  3. Create request to Google Maps with userโ€™s location info.
  4. Create request to TFL for bike information.
  5. Parse API response and add locations to map.

Advanced APIs

Building Our App - Steps

Bike map steps

Advanced APIs

1. Get User's Location

Advanced APIs

Navigator API

  • The Window.navigator property gives us reference to the Navigator object.
  • Navigator exposes data such as User Agent (Browser type) and Geolocation.

Advanced APIs

2. Render a Google map

Advanced APIs

Google Maps

Advanced APIs

3. Center Google Maps on userโ€™s location

Advanced APIs

4. Create request to TFL for bike information

Advanced APIs

Transport For London

TFL logo

LINK: TFL API docs

  • TFL provide real-time data about their transport network around London.
  • The open API is used by companies such as CityMapper.
  • Datasets are available for: Journey Planning, Disruptions, timetables, Fares and lots more.

Advanced APIs

Postman

Post man logo

LINK: TFL API > Run in Postman

  • Postman allows us send HTTP requests and view responses without a browser.
  • Highly customisable tool that allows us to develop APIs.
  • We can add Headers and other metadata to requests.

Advanced APIs

5. Parse API response and add locations to map

Advanced APIs

6. Create an information window for when a user selects a bike point

Exercise - TFL API

Exercise

Location

  • starter-code > 01-bike-map

Timing

20 mins

  1. Add image element to the InfoWindow content string with the source being the bike.jpg file in the images folder. Give this image element a class of 'bike'.
  2. Add the Total Number of Docks to the InfoWindow information as a new line in the InfoWindow. HINT: Use the NbDocks value from the bikePoint data.
  3. Add another line to the InfoWindow showing the number of available bikes as a percentage of the total number of Bikes. round this percentage to the nearest whole number: e.g: Bike Availabilty: 23%
  4. BONUS: Read the Google Maps docs on custom markers and add custom markers of your own (https://developers.google.com/maps/documentation/javascript/custom-markers) HINT: If you image size is too large, try using the scaled size property (https://stackoverflow.com/questions/15096461/resize-google-maps-marker-icon-image)

Advanced APIs

Learning Objective

Learning Objectives - Review

  • Request data from a web service.
  • Implement the geolocation API to request a location.
  • Use Postman to construct and test an API request.
  • Process a third-party API response and share location data on your website.
  • Search documentation needed to make and customise third-party API requests.

Advanced APIs

Look Ahead to Next Lesson

  • Familiarise yourself with the API documentation from the APIs list.
  • Fork and clone your starter code.
  • Strategise ways to hide the loader and replace the content of the #main container with that of the API.

Advanced APIs

API List - 1/2

Advanced APIs

API List - 2/2

Advanced APIs

Exit Ticket

(Lesson #12)