CHAPTER 9 APIS. CHAPTER 9 APIS WHAT IS AN API?

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

1 Chapter 12 Working With Access 2000 on the Internet.
Today Microformats and a sprinkling of RDF Everyone good with SVN? Everyone checked something in? No? Try now. Mobile – Functionality – UX If you get too.
CHAPTER 26 CREATING LOCATION-AWARE WEBPAGES USING GEOLOCATION.
THE BASICS OF THE WEB Davison Web Design. Introduction to the Web Main Ideas The Internet is a worldwide network of hardware. The World Wide Web is part.
Development of mobile applications using PhoneGap and HTML 5
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Modern JavaScript Develop And Design Instructor’s Notes Chapter 2- JavaScript in Action Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Presented by…. Group 2 1. Programming language 2Introduction.
Chapter 25 Utilizing Web Storage.
CS 174: Web Programming April 21 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
CHAP 4. GEOLOCATION API.  You can request users to share their location and, if they agree, you can provide them with instructions on how to get to a.
JavaScript & jQuery the missing manual Chapter 11
Joel Bapaga on Web Design Strategies Technologies Commercial Value.
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
INTRODUCTION TO HTML5 Geolocation. Display a Specific Location with Google Maps  You can use the Google Maps API to display a custom map on your own.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Cross Site Integration “mashups” cross site scripting.
CHAP 6. USING THE HTML5 WEB STORAGE API.  Cookie - Are a built-in way of sending text values back and forth from server to client.  Servers can use.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
Introduction to HTML. What is HTML?  Hyper Text Markup Language  Not a programming language but a markup language  Used for presentation and layout.
HTML5 AND THE FUTURE JAVASCRIPT PLATFORM Marcelo Lopez Ruiz Senior Software Design Engineer Microsoft Corporation.
Webview and Web services. Web Apps You can make your web content available to users in two ways in a traditional web browser in an Android application,
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
Chapter 1 Getting Started With Dreamweaver. Exploring the Dreamweaver Workspace The Dreamweaver workspace is where you can find all the tools to create.
HTML 5 Tutorial Chapter 6 Web Storage. Storing Data on The Client HTML5 offers two new objects for storing data on the client: localStorage - stores data.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
Rich Internet Applications 9. HTML 5 and RIAs. HTML 5 Standard currently under development by W3C Aims to improve the language with support for the latest.
Presented By Nanda Kumar(972789) P. Trinesh (982816) Sk. Salma (982824) K. Madhuri (982814) HTML5.
® ® copyright © 2013 Open Geospatial Consortium What HTML5 and REST mean to the Geo community Raj Singh, PhD Open Geospatial Consortium
JavaScript, Sixth Edition
Phonegap Bridge –Geolocation and Google maps CIS 136 Building Mobile Apps 1.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Using HTML5 to Build Offline Applications Woody Pewitt Icenium
APP DESIGN AND DEVELOPMENT WITH THE IONIC FRAMEWORK Chuck Leone
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
1 Bus Tracker A Google Maps Application. 22 Objectives You will be able to Add an icon to a map created with the Google Maps API. Use Ajax techniques.
Development of Internet Applications HTML5 Ing. Jan Janoušek 7.
The HTML5 logo was introduced by W3C in 2010
Chapter 17 The Need for HTML 5.
Chapter 4: Feature Detection & Drag and Drop
Web Technologies Computing Science Thompson Rivers University
JavaScript and Ajax (Ajax Tutorial)
DPS Dissertation System
Jim Fawcett CSE686 – Internet Programming Spring 2012
Active Server Pages Computer Science 40S.
User Interface Design and Usability jQuery, jQuery UI & jQuery Plugins
Section 17.1 Section 17.2 Add an audio file using HTML
Geolocation using Google maps
The Cliff Notes Version
Unit 27 - Web Server Scripting
The Application Lifecycle
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
Geolocation using Google maps
Integrating JavaScript and HTML
ISC440: Web Programming 2 AJAX
Web Programming Language
Technical Integration Guide
Web Technologies Computing Science Thompson Rivers University
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Web Client Side Technologies Raneem Qaddoura
Geolocation using Google maps
Presentation transcript:

CHAPTER 9 APIS

WHAT IS AN API?

API stands for Application Programming Interface.

User interfaces allow humans to interact with programs User interfaces allow humans to interact with programs. APIs let programs (and scripts) talk to each other.

You do not need to know how a program does something… So long as you know how to ask it to do something and process the response.

An API tells you how to ask a program to do something… As well as the format you can expect the response to be in.

HTML5 JAVASCRIPT APIS

As devices have evolved, browsers can access new: Hardware features such as GPS, accelerometers and cameras Software functionality such as storage objects, file API, canvas

Feature detection lets you check whether or not the browser supports a feature.

You can choose to only run the code if the feature is supported.

navigation.geolocation Is navigation.geolocation supported? N Y Run statements that do not use geolocation Run statements that use geolocation

Modernizr is a popular script that allows you to check if a feature is supported.

if (Modernizr.geolocation) { // Code to show location } else { // Not supported / turned off // Or user rejected }

GEOLOCATION API

Your visitor’s location can be requested using the geolocation API Your visitor’s location can be requested using the geolocation API. Users are asked if they want to share their location, and it is only shared if they consent.

PERMISSION REQUESTS

navigator.geolocation.getCurrentPosition(success, fail);

navigator.geolocation.getCurrentPosition(success, fail); The statement begins with the object that represents the browser: navigator.geolocation.getCurrentPosition(success, fail);

navigator.geolocation.getCurrentPosition(success, fail); A child of the navigator object then allows you to ask for the location:

navigator.geolocation.getCurrentPosition(success, fail); Next, a method of the geolocation object requests the position:

navigator.geolocation.getCurrentPosition(success, fail); The getCurrentPosition() method has two parameters: navigator.geolocation.getCurrentPosition(success, fail);

navigator.geolocation.getCurrentPosition(success, fail); The first is the name of a function to call if the location of the user has been retrieved successfully:

navigator.geolocation.getCurrentPosition(success, fail); The second is the name of a function to call if the location of the user has not been retrieved successfully:

If a request is successful, an object called position is returned. It has a child object called coords, which allows you to access properties for longitude and latitude. position.coords.longitude position.coords.latitude

If the request is not successful then a different message can be shown to the user instead.

This shows how APIs are often implemented using objects that have: Methods to do things Properties to tell you the characteristics of the object

So learning to use an API is often a matter of learning the objects it uses. Then what methods / properties you can use. What format the reply will come in.

WEB STORAGE API

Web storage (or HTML5 storage) lets you store data in the browser. The data it stores can only be accessed by the domain that set the data.

There are two types of storage: local and session storage. They are implemented using the localStorage and sessionStorage objects.

Both local and session storage have the same methods to get and set data, but each lasts a different amount of time.

LOCAL SESSION Stored when tab closed Y N All open windows / tabs Y N can access the data

Accessing the storage API: localStorage.setItem(key, value) sessionStorage.setItem(key, value) localStorage.getItem(key) sessionStorage.getItem(key)

HISTORY API

The history API stores which pages a user has visited The history API stores which pages a user has visited. It is implemented using the history object.

The history API allows Ajax applications to update the URL without loading an entirely new page.

HISTORY STACK: one.html one.html ONE TWO THREE 1

HISTORY STACK: two.html two.html ONE TWO THREE 2 one.html

HISTORY STACK: three.html three.html ONE TWO THREE 3 two.html one.html

HISTORY STACK: three.html three.html ONE TWO THREE 3 two.html one.html

HISTORY STACK: two.html two.html ONE TWO THREE 2 three.html one.html

Adding to the history object: Pages stored in the history object: history.pushState(state, title, url) Pages stored in the history object: history.back() history.forward() history.go()

The history object’s popstate event fires when the contents of the history object changes.

SCRIPTS WITH APIS

The jQuery Foundation maintains its own set of jQuery plugins called jQuery UI.

To make use of the jQuery UI set of plugins, you must first understand: How to structure your HTML The method to call to make it work

The HTML for the jQuery UI accordion is structured like this: <div id=”prizes”> <h3>1st Prize</h3> <div>First prize in the…</div> <h3>2nd Prize</h3> <div>Second prize is the…</div> <h3>3rd Prize</h3> <div>Third prize is the…</div> </div>

The script for the jQuery UI accordion is used like this: <script src=“jquery.js”></script> <script src=“jquery-ui.js”></script> <script> $(function() { $(‘prizes’).accordion(); } </script>

AngularJS is a framework that makes it easier to create web apps. In particular, it helps to create apps that read, write, update, and delete data in a database on the server.

AngularJS is based on a software development approach called Model View Controller or MVC.

MODEL VIEW CONTROLLER 1: Commands are sent up the chain to update the model 2: The data is synchronized to keep the view updated 3: Change notifications are sent back to the browser via the controller

Here is an example of AngularJS: <form> <input ng-model=“name” type=“text” /> <textarea ng-model=“message”> </textarea> </form> <div class=“postcard”> <div>{{ name }}</div> <p>{{ message }}</p> </div>

PLATFORM APIS

Large websites like Facebook, Google, and Twitter let you access and update data that is stored on their platform via APIs.

Google Maps allows you to add maps to your pages. High-traffic sites that use Google Maps need an API key, as there is a limit to the number of maps they will serve to a domain per day.

The HTML has an element that will be replaced by the map, and a link to a script: <div id=“map”></div> <script src=“js/google-map.js”> </script>

When the page is ready, the script is called: window.onload = loadScript;

It creates the <script> element to load the API from Google’s servers: function loadScript() { var script; script = document.createElement(‘script’); script.src = ‘http://maps.googleapis.com/ maps/api/js?sensor=false&callback=init’; document.body.appendChild(script); }

The init() function creates a mapOptions object to store map setup data: function init() { var mapOptions = { center: new google.maps.LatLng(40.782710,-73.965310), mapTypeId: google.maps.MapTypeId.ROADMAP, scaleControl: true, zoom: 13 }; var venueMap; var el = document.getElementById(‘map'); venueMap = new google.maps.Map(el, mapOptions); }

You can add to the mapOptions object to make the map more tailored to your needs.

styles: [ { stylers: [ { hue: "#00ff6f" }, { saturation: -50 } ] }, { featureType: "road", elementType: "geometry", { lightness: 100 }, { visibility: "simplified" } }