SlideShare a Scribd company logo
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?

More Related Content

What's hot

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)
Postman
 
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
Kevin Hazzard
 
eZ Publish REST API v2
eZ Publish REST API v2eZ Publish REST API v2
eZ Publish REST API v2
Bertrand Dunogier
 
E zsc2012 rest-api-v2
E zsc2012 rest-api-v2E zsc2012 rest-api-v2
E zsc2012 rest-api-v2
Bertrand Dunogier
 
Active server pages
Active server pagesActive server pages
Active server pages
student
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
Ankita Mahajan
 
ASP
ASPASP
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
Patrick Savalle
 
ASP
ASPASP
Introduction ASP
Introduction ASPIntroduction ASP
Introduction ASP
FaTin GhaZmi
 
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
Edureka!
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
mwinteringham
 
mule salesforce
mule salesforcemule salesforce
mule salesforce
F K
 
Asp
AspAsp
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
Aniruddh Bhilvare
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
Nitin Pande
 
REST, RESTful API
REST, RESTful APIREST, RESTful API
REST, RESTful API
Hossein Baghayi
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
Chalermpon Areepong
 
More Asp
More AspMore Asp
More Asp
guest4c97670
 
Web api
Web apiWeb api
Web api
udaiappa
 

What's hot (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
 

Similar to 05 Web Services

08 ajax
08 ajax08 ajax
08 ajax
Ynon Perek
 
Ajax
AjaxAjax
Ds
DsDs
Ds
Ma Kik
 
web programming
web programmingweb programming
web programming
shreeuva
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
dominion
 
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
Matt O'Keefe
 
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
Geoffrey Fox
 
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
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web Services
Angelin R
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
Pratik Tambekar
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
Chamnap Chhorn
 
Ajax
AjaxAjax
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Servlet basics
Servlet basicsServlet basics
Servlet basics
Santosh Dhoundiyal
 
Spicing up SharePoint web parts
Spicing up SharePoint web partsSpicing up SharePoint web parts
Spicing up SharePoint web parts
Randy Williams
 
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)
Prof Ansari
 
Mashup
MashupMashup
Mashup
Naveen P.N
 
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
 
Web services Concepts
Web services ConceptsWeb services Concepts
Web services Concepts
pasam suresh
 
Apitesting.pptx
Apitesting.pptxApitesting.pptx
Apitesting.pptx
NamanVerma88
 

Similar to 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
 

More from crgwbr

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
crgwbr
 
07 Integration Project Part 1
07 Integration Project Part 107 Integration Project Part 1
07 Integration Project Part 1
crgwbr
 
06 Map Reduce
06 Map Reduce06 Map Reduce
06 Map Reduce
crgwbr
 
04 Advanced Javascript
04 Advanced Javascript04 Advanced Javascript
04 Advanced Javascript
crgwbr
 
03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuery
crgwbr
 
02 Introduction to Javascript
02 Introduction to Javascript02 Introduction to Javascript
02 Introduction to Javascript
crgwbr
 
01 Introduction To CSS
01 Introduction To CSS01 Introduction To CSS
01 Introduction To CSS
crgwbr
 
08 Integration Project Part 2
08 Integration Project Part 208 Integration Project Part 2
08 Integration Project Part 2
crgwbr
 

More from 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
 

Recently uploaded

Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Discover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched ContentDiscover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched Content
ScyllaDB
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
ScyllaDB
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
FilipTomaszewski5
 

Recently uploaded (20)

Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Discover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched ContentDiscover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched Content
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
 

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?