SlideShare une entreprise Scribd logo
1  sur  15
HTML 5 and REST services
Building Rich HTML & JavaScript Clients
using REST services

Maurice de Beijer
Objectives

• Why build HTML client applications
• What did we cover in part 1?
    – What are REST services
    – The WCF Web API framework
•   Using a rich .NET client
•   Requesting resources in the proper format
•   Loading data from the service
•   Caching
•   JavaScript Templates
•   HTTP Methods
•   Authentication
Why build HTML client applications

• People are using multiple different devices
   – Desktop computers
   – Tablets
   – Smart phones
• Companies are changing
   – Bring your own device is the new mantra
• Different manufacturers use different technologies
   – But HTML is supported by all of them
What are REST services

• Representational State Transfer
  • Roy Thomas Fielding
• All about resources
   – CRUD style actions
• Embraces HTTP
   –   URLS
   –   MIME Media Types
   –   HTTP Methods
   –   Caching
   –   Security
• Enables very scalable services
   – Build around the technology that powers the Internet
The WCF Web API framework

• On CodePlex
   – http://wcf.codeplex.com/wikipage?title=WCF%20HTTP
• Use NuGet from within Visual Studio 2010
   – http://nuget.org/
• Current version 0.5
• Much better than the original WCF support for REST
   – But doesn’t replace it
Using a rich .NET client is easy

• Use the HttpClient
   – Part of the WCF Web API framework
• Or use any other standard HTTP client
   – The WebClient
   – The HttpWebRequest
• Other environments have similar types
   –   HttpURLConnection in Java
   –   NSURLConnection in Objective C
   –   fopen in PHP
   –   urllib in Python
   –   ...
Requesting resources in the proper format

• HTTP/REST use the Accept header to specify the mime
  type
• We can return the book resource as an image
   – Done with a custom MediaTypeFormatter
• Some browsers prefer PNG in an <img> tag
   – But will accept any image
   – Use the AddMediaRangeMapping() extension method.
• Some browser will accept anything in an <img> tag
   – Use the query string to specify the type.
   – Use the AddQueryStringMapping() extension method.
Loading data from the service

• JSON is the data format of choice
   – JavaScript Object Notation
• Use the XMLHTTPRequest object
   – jQuery makes this very easy
• jQuery.getJSON()
   – Load JSON data using an asynchronous HTTP GET request
• jQuery.ajax()
   – Perform an asynchronous HTTP (Ajax) request
   – Uses an options object that configure the Ajax request
Caching

• Caching can make a service much more scalable
   – REST services can use the standard HTTP caching infrastructure
• Some browsers cache results by default
   – Use $.ajax() with {cache: false}
   – Even better is to control caching.
      • set the response.Headers.CacheControl
JavaScript Templates

• Creating HTML elements in JavaScript can be tedious
• Templates can make a rich UI much easier
• JavaScript Micro-Templating
   – By John Resig, the inventor of jQuery
• Underscore library template
   – _.template()
• jQuery UI is working on a jQuery standard plugin
HTTP Methods

• GET and POST are no problem
• PUT and DELETE are not supported in most browsers
   – When used as a <form> method
   – Not part of the HTML specifications
   – Works fine with $.ajax() with type: ‘put’
• Sometimes firewalls also block PUT and DELETE
   – Use HTTP Method tunneling
   – Pus the method in the X-HTTP-Method-Override HTTP header
   – Use the HttpMethodTunnelChannel from WCF Web API Contrib
Authentication

• Lots of different options
   – OAuth
   – Basic authentication
   – Intergrated autentication
• Return a 401 – Unauthorized
   – When a client needs to provide credentials
• The FormsAuthenticationModule intercepts the 401
   – The browser receives a 307 - Redirect to the login page
   – See: Prevent Forms Authentication Login Page Redirect When You
     Don’t Want It by Phil Haack
Useful resources 1

• jQuery
  http://jquery.com/
• jQuery UI
  http://jqueryui.com/
• JavaScript Micro-Templating
  http://ejohn.org/blog/javascript-micro-templating/
• Underscore.js
  http://documentcloud.github.com/underscore/
• Modernizr
  http://www.modernizr.com/
Useful resources 2

• Essential Windows Communication Foundation 4 Training
   – http://www.develop.com/training-course/windows-
     communication-foundation-wcf
• Hypertext Transfer Protocol -- HTTP/1.1
   – http://tools.ietf.org/html/rfc2616
• The Atom Syndication Format
   – http://tools.ietf.org/html/rfc4287
• The Atom Publishing Protocol
   – http://tools.ietf.org/html/rfc5023
• Open Data Protocol (OData)
   – http://www.odata.org
• WCF Web API Contrib
   – http://webapicontrib.codeplex.com
• Fiddler
   – http://www.fiddler2.com
Summary

• HTML/JavaScript clients are important
   – You can no longer depend on Windows as the client
• The browsers isn’t as smart as you would expect
   – Accepts anything as the source in an image element
   – Form elements only support GET and POST
   – Caching of requests depends on the browsers
• Sometimes ASP.NET isn’t as smart as we would like
   – Changes a 401 – Unauthorized to a 307 – Redirect
• jQuery and jQuery UI are extremely useful
   – Don’t forget about Underscore.js and Modernizr

Contenu connexe

En vedette

20160307 apex connects_jira
20160307 apex connects_jira20160307 apex connects_jira
20160307 apex connects_jiraMT AG
 
UC SDN
UC SDNUC SDN
UC SDNIMTC
 
Managing Product Growth Experiments With JIRA and Confluence - Zane Salim
Managing Product Growth Experiments With JIRA and Confluence - Zane SalimManaging Product Growth Experiments With JIRA and Confluence - Zane Salim
Managing Product Growth Experiments With JIRA and Confluence - Zane SalimAtlassian
 
APEX connects Jira
APEX connects JiraAPEX connects Jira
APEX connects JiraOliver Lemm
 
JIRA Performance After 300,000 Issues
JIRA Performance After 300,000 IssuesJIRA Performance After 300,000 Issues
JIRA Performance After 300,000 IssuesAtlassian
 
Jira plugin dev introduction 14012014 a
Jira plugin dev introduction 14012014 aJira plugin dev introduction 14012014 a
Jira plugin dev introduction 14012014 alukasgotter
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIEyal Vardi
 
Web 2.0 Mashups
Web 2.0 MashupsWeb 2.0 Mashups
Web 2.0 Mashupshchen1
 
Agile Overview Session
Agile Overview SessionAgile Overview Session
Agile Overview SessionBahaa Farouk
 
Using JIRA & Greenhopper for Agile Development
Using JIRA & Greenhopper for Agile DevelopmentUsing JIRA & Greenhopper for Agile Development
Using JIRA & Greenhopper for Agile DevelopmentJeff Leyser
 
Rest API Security
Rest API SecurityRest API Security
Rest API SecurityStormpath
 
6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your BusinessFabernovel
 
Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms Timothy Spann
 
JIRA-An intro
JIRA-An introJIRA-An intro
JIRA-An introAsha G.K.
 

En vedette (18)

20160307 apex connects_jira
20160307 apex connects_jira20160307 apex connects_jira
20160307 apex connects_jira
 
Jira
JiraJira
Jira
 
UC SDN
UC SDNUC SDN
UC SDN
 
Managing Product Growth Experiments With JIRA and Confluence - Zane Salim
Managing Product Growth Experiments With JIRA and Confluence - Zane SalimManaging Product Growth Experiments With JIRA and Confluence - Zane Salim
Managing Product Growth Experiments With JIRA and Confluence - Zane Salim
 
APEX connects Jira
APEX connects JiraAPEX connects Jira
APEX connects Jira
 
UC Browser
UC BrowserUC Browser
UC Browser
 
JIRA Performance After 300,000 Issues
JIRA Performance After 300,000 IssuesJIRA Performance After 300,000 Issues
JIRA Performance After 300,000 Issues
 
Jira plugin dev introduction 14012014 a
Jira plugin dev introduction 14012014 aJira plugin dev introduction 14012014 a
Jira plugin dev introduction 14012014 a
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
Web 2.0 Mashups
Web 2.0 MashupsWeb 2.0 Mashups
Web 2.0 Mashups
 
Jira Agile
Jira AgileJira Agile
Jira Agile
 
Agile Overview Session
Agile Overview SessionAgile Overview Session
Agile Overview Session
 
Using JIRA & Greenhopper for Agile Development
Using JIRA & Greenhopper for Agile DevelopmentUsing JIRA & Greenhopper for Agile Development
Using JIRA & Greenhopper for Agile Development
 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms
 
JIRA-An intro
JIRA-An introJIRA-An intro
JIRA-An intro
 

Plus de Maurice De Beijer [MVP]

Practice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components AppPractice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components AppMaurice De Beijer [MVP]
 
A foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software ProjectA foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software ProjectMaurice De Beijer [MVP]
 
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using CypressSurati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using CypressMaurice De Beijer [MVP]
 
Build reliable Svelte applications using Cypress
Build reliable Svelte applications using CypressBuild reliable Svelte applications using Cypress
Build reliable Svelte applications using CypressMaurice De Beijer [MVP]
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureMaurice De Beijer [MVP]
 
Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Maurice De Beijer [MVP]
 
Building reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and AzureBuilding reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and AzureMaurice De Beijer [MVP]
 
Building large and scalable mission critical applications with React
Building large and scalable mission critical applications with ReactBuilding large and scalable mission critical applications with React
Building large and scalable mission critical applications with ReactMaurice De Beijer [MVP]
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureMaurice De Beijer [MVP]
 
Building reliable web applications using Cypress
Building reliable web applications using CypressBuilding reliable web applications using Cypress
Building reliable web applications using CypressMaurice De Beijer [MVP]
 
Getting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent renderingGetting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent renderingMaurice De Beijer [MVP]
 
React suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred HitchcockReact suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred HitchcockMaurice De Beijer [MVP]
 
From zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScriptFrom zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScriptMaurice De Beijer [MVP]
 
From zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScriptFrom zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScriptMaurice De Beijer [MVP]
 
Create flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisCreate flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisMaurice De Beijer [MVP]
 

Plus de Maurice De Beijer [MVP] (20)

Practice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components AppPractice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components App
 
A foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software ProjectA foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software Project
 
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using CypressSurati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
 
Build reliable Svelte applications using Cypress
Build reliable Svelte applications using CypressBuild reliable Svelte applications using Cypress
Build reliable Svelte applications using Cypress
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & Azure
 
Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18
 
Building reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and AzureBuilding reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and Azure
 
Building large and scalable mission critical applications with React
Building large and scalable mission critical applications with ReactBuilding large and scalable mission critical applications with React
Building large and scalable mission critical applications with React
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & Azure
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
Building reliable web applications using Cypress
Building reliable web applications using CypressBuilding reliable web applications using Cypress
Building reliable web applications using Cypress
 
Getting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent renderingGetting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent rendering
 
React suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred HitchcockReact suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred Hitchcock
 
From zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScriptFrom zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScript
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
The new React
The new React The new React
The new React
 
From zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScriptFrom zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScript
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
I am hooked on React
I am hooked on ReactI am hooked on React
I am hooked on React
 
Create flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisCreate flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apis
 

Dernier

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 

Dernier (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Building rich HTML 5 clients using REST services

  • 1. HTML 5 and REST services Building Rich HTML & JavaScript Clients using REST services Maurice de Beijer
  • 2. Objectives • Why build HTML client applications • What did we cover in part 1? – What are REST services – The WCF Web API framework • Using a rich .NET client • Requesting resources in the proper format • Loading data from the service • Caching • JavaScript Templates • HTTP Methods • Authentication
  • 3. Why build HTML client applications • People are using multiple different devices – Desktop computers – Tablets – Smart phones • Companies are changing – Bring your own device is the new mantra • Different manufacturers use different technologies – But HTML is supported by all of them
  • 4. What are REST services • Representational State Transfer • Roy Thomas Fielding • All about resources – CRUD style actions • Embraces HTTP – URLS – MIME Media Types – HTTP Methods – Caching – Security • Enables very scalable services – Build around the technology that powers the Internet
  • 5. The WCF Web API framework • On CodePlex – http://wcf.codeplex.com/wikipage?title=WCF%20HTTP • Use NuGet from within Visual Studio 2010 – http://nuget.org/ • Current version 0.5 • Much better than the original WCF support for REST – But doesn’t replace it
  • 6. Using a rich .NET client is easy • Use the HttpClient – Part of the WCF Web API framework • Or use any other standard HTTP client – The WebClient – The HttpWebRequest • Other environments have similar types – HttpURLConnection in Java – NSURLConnection in Objective C – fopen in PHP – urllib in Python – ...
  • 7. Requesting resources in the proper format • HTTP/REST use the Accept header to specify the mime type • We can return the book resource as an image – Done with a custom MediaTypeFormatter • Some browsers prefer PNG in an <img> tag – But will accept any image – Use the AddMediaRangeMapping() extension method. • Some browser will accept anything in an <img> tag – Use the query string to specify the type. – Use the AddQueryStringMapping() extension method.
  • 8. Loading data from the service • JSON is the data format of choice – JavaScript Object Notation • Use the XMLHTTPRequest object – jQuery makes this very easy • jQuery.getJSON() – Load JSON data using an asynchronous HTTP GET request • jQuery.ajax() – Perform an asynchronous HTTP (Ajax) request – Uses an options object that configure the Ajax request
  • 9. Caching • Caching can make a service much more scalable – REST services can use the standard HTTP caching infrastructure • Some browsers cache results by default – Use $.ajax() with {cache: false} – Even better is to control caching. • set the response.Headers.CacheControl
  • 10. JavaScript Templates • Creating HTML elements in JavaScript can be tedious • Templates can make a rich UI much easier • JavaScript Micro-Templating – By John Resig, the inventor of jQuery • Underscore library template – _.template() • jQuery UI is working on a jQuery standard plugin
  • 11. HTTP Methods • GET and POST are no problem • PUT and DELETE are not supported in most browsers – When used as a <form> method – Not part of the HTML specifications – Works fine with $.ajax() with type: ‘put’ • Sometimes firewalls also block PUT and DELETE – Use HTTP Method tunneling – Pus the method in the X-HTTP-Method-Override HTTP header – Use the HttpMethodTunnelChannel from WCF Web API Contrib
  • 12. Authentication • Lots of different options – OAuth – Basic authentication – Intergrated autentication • Return a 401 – Unauthorized – When a client needs to provide credentials • The FormsAuthenticationModule intercepts the 401 – The browser receives a 307 - Redirect to the login page – See: Prevent Forms Authentication Login Page Redirect When You Don’t Want It by Phil Haack
  • 13. Useful resources 1 • jQuery http://jquery.com/ • jQuery UI http://jqueryui.com/ • JavaScript Micro-Templating http://ejohn.org/blog/javascript-micro-templating/ • Underscore.js http://documentcloud.github.com/underscore/ • Modernizr http://www.modernizr.com/
  • 14. Useful resources 2 • Essential Windows Communication Foundation 4 Training – http://www.develop.com/training-course/windows- communication-foundation-wcf • Hypertext Transfer Protocol -- HTTP/1.1 – http://tools.ietf.org/html/rfc2616 • The Atom Syndication Format – http://tools.ietf.org/html/rfc4287 • The Atom Publishing Protocol – http://tools.ietf.org/html/rfc5023 • Open Data Protocol (OData) – http://www.odata.org • WCF Web API Contrib – http://webapicontrib.codeplex.com • Fiddler – http://www.fiddler2.com
  • 15. Summary • HTML/JavaScript clients are important – You can no longer depend on Windows as the client • The browsers isn’t as smart as you would expect – Accepts anything as the source in an image element – Form elements only support GET and POST – Caching of requests depends on the browsers • Sometimes ASP.NET isn’t as smart as we would like – Changes a 401 – Unauthorized to a 307 – Redirect • jQuery and jQuery UI are extremely useful – Don’t forget about Underscore.js and Modernizr