SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
Web Services
Web Development 101
Lesson 04.01
Client-side is only half
of the web stack.
WEB ARCHITECTURE
ANATOMY OF AN HTTP REQUEST / RESPONSE PAIR
SAMPLE HTTP RESPONSE
http://www.jw.org/en/publication
Every web page is the result
of an HTTP transaction
Architect: Web Email Client
Entirely Web Based Email Client
Application


Clicking a folder displays the
contents of the folder


Loading the application displays
the inbox


Clicking the compose button
displays a modal window to
write a new email

Clicking on any of the messages
displays the content of the
message
AJAX
Asynchronous Javascript and XML
AJAX

JSON
Asynchronous Javascript and XML
AJAX IN USE
Web APIs
Application Programming Interface (API).

Can use any data format—normally JSON is preferred.

Aim to provide data to Applications, rather than full web-pages.

Should use HTTP Verbs Semantically
Example 04.01.01
http://jsfiddle.net/crgwbr/vS88d/
Asynchronous execution
Simulated Concurrency
gettingContent = $.getJSON(url);	
gettingContent.done(function (data) {
console.log(1);
});
!

console.log(2);
var url = BASE_URL + vid + "?callback=?",	
gettingContent = $.getJSON(url);
Same-origin policy
Enforced by all major browsers

Prevents AJAX calls from being made to other domains

Web apps can’t (by default) call APIs on another domain
Subverting | Same-origin Policy
Cross Origin Resource Sharing
Javascript (example1.com) makes request to API (example2.com)

Browser includes origin header stating where the JS is from

Origin: http://www.example1.com	

API decides http://www.example1.com is OK

Response includes Access-Control-Allow-Origin header

Access-Control-Allow-Origin: http://www.example1.com	

Browser allows request to finish when it sees the allow header
CORS Pitfalls
Recent addition to HTTP spec

All [new] API’s should support it, but don’t expect browser’s to

CORS is the way of the future and the proper way to share
resources, but still to unreliable.
JSON with Padding (JSONP)
Exploits a loop-hole in browser security

Supported by all browsers and is commonly used.

Plan on using only as a patch until CORS support is better.

Only supports making GET requests
JSONP
Browser creates script tag with API Resource as src

<script src=”http://www.jw.org/01001001?callback=abcdef”></script>	

Browsers have no problem with this

Server responds with JSON wrapped in a function call.

abcdef({“hello”: “world”});	

Browser executes code, resulting in function call with object passed as a
param.

jQuery’s $.getJSON does this automatically by adding callback=? to the URL
HTTP Verbs
Semantic Meaning and Use
HTTP Verbs
Describe the what the client is attempting to accomplish with the
request.

Basic Verbs: GET, POST, HEAD

Recently Added: PUT, PATCH, DELETE
Idempotent
[adjective]

Describes an operation that can be applied multiple times without
changing the result beyond the initial application.
i = 0

i = 0

!

!

f (x) ->
x + (i + 1);

f (x) ->
x + (++i);

>>> f(1)	
2	
>>> f(1)	
2	
>>> f(1)	
2

>>> f(1)	
2	
>>> f(1)	
3	
>>> f(1)	
4
GET: Request data from the server. Request is read-only and
idempotent.

POST: Save data from the client to the server. Request involves a write
and is not idempotent.

HEAD: Same as GET, but only return the HTTP Headers.
PUT: Replace existing data with data from the client. Request involves
writes, but is idempotent.

PATCH: Replace part of the existing data with data from the client.
Request involves writes, but is idempotent.

DELETE: Delete the specified data. Request involves writes, but is
idempotent.
Which verb would be correct?
Request the body of an email from the server

Send a new email

Delete an email

Save a new message draft

Update an existing message draft

Move an email to a new folder
Example 04.01.02
Bible Reading Application
jw.org Bible API
Editions Endpoint	
GET http://www.jw.org/en/publications/bible/json/	
Lists available Bible Editions and Languages	
Contains english and vernacular language names	
Contains links to Books Endpoint	
!
Books Endpoint	
GET http://www.jw.org/en/publications/bible/nwt/books/json/	
Lists available books in the given language/edition	
!
Verse Range Endpoint	
GET http://www.jw.org/en/publications/bible/nwt/books/json/html/01001001	
Returns rendered verse range	
Verse ID is 8 digits: <booknum><chapterNum><verseNum>	
Supports ranges with: <VerseID>-<VerseID>
Current Functionality

Hits jw.org Edition API

Lists available languages
New Requirements

Sort language list

English should still be the default
New Requirements
Add selects for:

Editions within a language

Books and chapters within an edition

All select filters should automatically update other select boxes’ values
Review
What kind of protocol is HTTP? 

What’s a Web API?


What are HTTP Verbs?


How do JS Apps access Web
APIs?


What are each of the HTTP
Verbs used for?


What can AJAX be used for?


What’s the Same Origin Policy?


How does JS handle
asynchronous events?


How do you get around it?

Mais conteúdo relacionado

Mais procurados

Active server pages
Active server pagesActive server pages
Active server pages
student
 

Mais procurados (20)

Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 
eZ Publish REST API v2
eZ Publish REST API v2eZ Publish REST API v2
eZ Publish REST API v2
 
E zsc2012 rest-api-v2
E zsc2012 rest-api-v2E zsc2012 rest-api-v2
E zsc2012 rest-api-v2
 
Active server pages
Active server pagesActive server pages
Active server pages
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
ASP
ASPASP
ASP
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
ASP
ASPASP
ASP
 
Introduction ASP
Introduction ASPIntroduction ASP
Introduction ASP
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
 
mule salesforce
mule salesforcemule salesforce
mule salesforce
 
Asp
AspAsp
Asp
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
 
REST, RESTful API
REST, RESTful APIREST, RESTful API
REST, RESTful API
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
More Asp
More AspMore Asp
More Asp
 
Web api
Web apiWeb api
Web api
 

Semelhante a 05 Web Services

Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
dominion
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
Adil Mughal
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
Chamnap Chhorn
 
Asynchronous reading and writing http r equest
Asynchronous reading and writing http r equestAsynchronous reading and writing http r equest
Asynchronous reading and writing http r equest
Pragyanshis Patnaik
 

Semelhante a 05 Web Services (20)

08 ajax
08 ajax08 ajax
08 ajax
 
Ajax
AjaxAjax
Ajax
 
Ds
DsDs
Ds
 
web programming
web programmingweb programming
web programming
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web Services
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
 
Ajax
AjaxAjax
Ajax
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
 
Spicing up SharePoint web parts
Spicing up SharePoint web partsSpicing up SharePoint web parts
Spicing up SharePoint web parts
 
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
 
Mashup
MashupMashup
Mashup
 
Asynchronous reading and writing http r equest
Asynchronous reading and writing http r equestAsynchronous reading and writing http r equest
Asynchronous reading and writing http r equest
 
Web services Concepts
Web services ConceptsWeb services Concepts
Web services Concepts
 
Apitesting.pptx
Apitesting.pptxApitesting.pptx
Apitesting.pptx
 

Mais de crgwbr (8)

Lightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with BrowserifyLightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with Browserify
 
07 Integration Project Part 1
07 Integration Project Part 107 Integration Project Part 1
07 Integration Project Part 1
 
06 Map Reduce
06 Map Reduce06 Map Reduce
06 Map Reduce
 
04 Advanced Javascript
04 Advanced Javascript04 Advanced Javascript
04 Advanced Javascript
 
03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuery
 
02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascript
 
01 Introduction To CSS
01 Introduction To CSS01 Introduction To CSS
01 Introduction To CSS
 
08 Integration Project Part 2
08 Integration Project Part 208 Integration Project Part 2
08 Integration Project Part 2
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
Safe Software
 

Último (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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...
 

05 Web Services

  • 1. Web Services Web Development 101 Lesson 04.01
  • 2. Client-side is only half of the web stack.
  • 4. ANATOMY OF AN HTTP REQUEST / RESPONSE PAIR
  • 6. Every web page is the result of an HTTP transaction
  • 7. Architect: Web Email Client Entirely Web Based Email Client Application Clicking a folder displays the contents of the folder Loading the application displays the inbox Clicking the compose button displays a modal window to write a new email Clicking on any of the messages displays the content of the message
  • 11. Web APIs Application Programming Interface (API). Can use any data format—normally JSON is preferred. Aim to provide data to Applications, rather than full web-pages. Should use HTTP Verbs Semantically
  • 14. gettingContent = $.getJSON(url); gettingContent.done(function (data) { console.log(1); }); ! console.log(2);
  • 15. var url = BASE_URL + vid + "?callback=?", gettingContent = $.getJSON(url);
  • 16. Same-origin policy Enforced by all major browsers Prevents AJAX calls from being made to other domains Web apps can’t (by default) call APIs on another domain
  • 18. Cross Origin Resource Sharing Javascript (example1.com) makes request to API (example2.com) Browser includes origin header stating where the JS is from Origin: http://www.example1.com API decides http://www.example1.com is OK Response includes Access-Control-Allow-Origin header Access-Control-Allow-Origin: http://www.example1.com Browser allows request to finish when it sees the allow header
  • 19. CORS Pitfalls Recent addition to HTTP spec All [new] API’s should support it, but don’t expect browser’s to CORS is the way of the future and the proper way to share resources, but still to unreliable.
  • 20. JSON with Padding (JSONP) Exploits a loop-hole in browser security Supported by all browsers and is commonly used. Plan on using only as a patch until CORS support is better. Only supports making GET requests
  • 21. JSONP Browser creates script tag with API Resource as src <script src=”http://www.jw.org/01001001?callback=abcdef”></script> Browsers have no problem with this Server responds with JSON wrapped in a function call. abcdef({“hello”: “world”}); Browser executes code, resulting in function call with object passed as a param. jQuery’s $.getJSON does this automatically by adding callback=? to the URL
  • 23. HTTP Verbs Describe the what the client is attempting to accomplish with the request. Basic Verbs: GET, POST, HEAD Recently Added: PUT, PATCH, DELETE
  • 24. Idempotent [adjective] Describes an operation that can be applied multiple times without changing the result beyond the initial application.
  • 25. i = 0 i = 0 ! ! f (x) -> x + (i + 1); f (x) -> x + (++i); >>> f(1) 2 >>> f(1) 2 >>> f(1) 2 >>> f(1) 2 >>> f(1) 3 >>> f(1) 4
  • 26. GET: Request data from the server. Request is read-only and idempotent. POST: Save data from the client to the server. Request involves a write and is not idempotent. HEAD: Same as GET, but only return the HTTP Headers.
  • 27. PUT: Replace existing data with data from the client. Request involves writes, but is idempotent. PATCH: Replace part of the existing data with data from the client. Request involves writes, but is idempotent. DELETE: Delete the specified data. Request involves writes, but is idempotent.
  • 28. Which verb would be correct? Request the body of an email from the server Send a new email Delete an email Save a new message draft Update an existing message draft Move an email to a new folder
  • 30. jw.org Bible API Editions Endpoint GET http://www.jw.org/en/publications/bible/json/ Lists available Bible Editions and Languages Contains english and vernacular language names Contains links to Books Endpoint ! Books Endpoint GET http://www.jw.org/en/publications/bible/nwt/books/json/ Lists available books in the given language/edition ! Verse Range Endpoint GET http://www.jw.org/en/publications/bible/nwt/books/json/html/01001001 Returns rendered verse range Verse ID is 8 digits: <booknum><chapterNum><verseNum> Supports ranges with: <VerseID>-<VerseID>
  • 31. Current Functionality Hits jw.org Edition API Lists available languages
  • 32. New Requirements Sort language list English should still be the default
  • 33. New Requirements Add selects for: Editions within a language Books and chapters within an edition All select filters should automatically update other select boxes’ values
  • 34. Review What kind of protocol is HTTP? What’s a Web API? What are HTTP Verbs? How do JS Apps access Web APIs? What are each of the HTTP Verbs used for? What can AJAX be used for? What’s the Same Origin Policy? How does JS handle asynchronous events? How do you get around it?