Web Services
An Introduction
Monday, September 23, 13
Web Services
What Do They Do?
How Do They Work?
Wrap-Up
HTTP
Payload
Headers
Flavors
Discovery
ToolsReferences
Questions
M...
What Do They Do?
• What don’t they do?
• Heavily used technology
• Everyone knows the Web
• Lots of developers create for ...
Out in the World
• Most Web applications use Web Services
• Many mobile apps use them
• Many desktop applications use them...
How Do They Work?
• A suite of standard technologies:
• HTTP
• URL
• JSON, XML, YAML, etc.
• DNS
Monday, September 23, 13
HTTP
• Request
• URL
• Method
• Headers
• Payload
• Response
• Status Code
• Headers
• Payload
• HTTP is stateless!
Monday...
URL
https://mypropaq.zoll.local:443/Loc/Res?Qry#Frag
Protocol
Subdomain
Domain
Top-Level
Domain
Port
“Location”
Resource
Q...
HTTP Methods
• Most Common
•GET
•POST
•PUT
•DELETE
• Less Used
•HEAD
•OPTIONS
•CONNECT
•TRACE
•PATCH
Monday, September 23,...
HTTP Status Codes
• All 3 digit numbers
• 1xx: Informational
• 2xx: Success
• 3xx: Redirection
• 4xx: Your Fault
• 5xx: Ou...
HTTP Headers
• A set of key-value pairs
• There is an official set of keys
• Convention enforces the correct use of keys
•...
Payload
• Can be anything needed, of any size
• Can be compressed
• Can have an MD5 checksum applied to it
• Can be chunke...
Payload Formats
• A handful of textual formats are popular:
• CSV, INI, JSON, RDF, TSV, TXT, XML, YAML
• For data: CSV, RD...
Why JSON?
[Test]
DC.Title = Test Data File
DC.Description = Simple test to compare INI, JSON, XML, and YAML.
DC.Creator = ...
Read - Parse - Write & Size Comparisons
(naïve & unscientific)
% ./testINI.py
10.1204838753
% ./testJSON.py
8.89217090607
...
Flavors
• A handful of popular options:
• SOAP
• XML-RPC
• JSON-RPC
• REST
• REST is quickly becoming the most popular
Mon...
Why REST?
Request:
POST /GetEvent HTTP/1.1
Host: www.example.org
Date: Wed, 31 Aug 2011 12:23:00 GMT
Content-Type: applica...
Streaming
• Chunking is good for large uploads or downloads
• Not sufficient for two-way communications
• Request / Respon...
Discovery
• mDNS
• also called Bonjour, Avahi,
Rendevous, & Zeroconf
• DNS
• NIS
• hosts file
Monday, September 23, 13
Tools
• One of the beauties of following standards: other
people write the tools
• A Web service call can be made via a br...
Wrap-Up
• Following standards is good
• One benefits from the work of
others
• Others can more easily use
your products
Mo...
References
• http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
• http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htm...
Upcoming SlideShare
Loading in …5
×

Web Services Introduction

590 views

Published on

A quick introduction to Web services.

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
590
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Web Services Introduction

  1. 1. Web Services An Introduction Monday, September 23, 13
  2. 2. Web Services What Do They Do? How Do They Work? Wrap-Up HTTP Payload Headers Flavors Discovery ToolsReferences Questions Monday, September 23, 13
  3. 3. What Do They Do? • What don’t they do? • Heavily used technology • Everyone knows the Web • Lots of developers create for the Web Monday, September 23, 13
  4. 4. Out in the World • Most Web applications use Web Services • Many mobile apps use them • Many desktop applications use them • Even some command-line programs do Monday, September 23, 13
  5. 5. How Do They Work? • A suite of standard technologies: • HTTP • URL • JSON, XML, YAML, etc. • DNS Monday, September 23, 13
  6. 6. HTTP • Request • URL • Method • Headers • Payload • Response • Status Code • Headers • Payload • HTTP is stateless! Monday, September 23, 13
  7. 7. URL https://mypropaq.zoll.local:443/Loc/Res?Qry#Frag Protocol Subdomain Domain Top-Level Domain Port “Location” Resource Query Fragment Most Components are Optional Monday, September 23, 13
  8. 8. HTTP Methods • Most Common •GET •POST •PUT •DELETE • Less Used •HEAD •OPTIONS •CONNECT •TRACE •PATCH Monday, September 23, 13
  9. 9. HTTP Status Codes • All 3 digit numbers • 1xx: Informational • 2xx: Success • 3xx: Redirection • 4xx: Your Fault • 5xx: Our Fault Monday, September 23, 13
  10. 10. HTTP Headers • A set of key-value pairs • There is an official set of keys • Convention enforces the correct use of keys • Handles authentication, caching, checksums, chunking, compression, cookies, formats, and sessions Monday, September 23, 13
  11. 11. Payload • Can be anything needed, of any size • Can be compressed • Can have an MD5 checksum applied to it • Can be chunked into multiple pieces for easier consumption Monday, September 23, 13
  12. 12. Payload Formats • A handful of textual formats are popular: • CSV, INI, JSON, RDF, TSV, TXT, XML, YAML • For data: CSV, RDF, TSV, TXT, & XML are popular • For configuration: INI, JSON, & YAML are popular • For documents: JSON, TXT, & XML are popular • For communications: JSON is most popular Monday, September 23, 13
  13. 13. Why JSON? [Test] DC.Title = Test Data File DC.Description = Simple test to compare INI, JSON, XML, and YAML. DC.Creator = Eric W. Brown DC.Identifier = 1 DC.Subject[1] = Test DC.Subject[2] = INI DC.Subject[3] = JSON DC.Subject[4] = XML DC.Subject[5] = YAML DC.Subject[6] = Text DC.Type = Dataset DC.Coverage = Basic comparison of textual formats DC.Contributors[1] = Eric W. Brown DC.Language = en-US DC.Date = 2013/09/13 08:19:14.764159 GMT-4 DC.Rights = All Rights Reserved DC.Publisher = ZOLL Version = 1.0 INI { "DC.Title": "Test Data File", "DC.Description": "Simple test to compare INI, JSON, XML, and YAML.", "DC.Creator": "Eric W. Brown", "DC.Identifier": 1, "DC.Subject": ["Test", "INI", "JSON", "XML", "YAML", "Text"], "DC.Type": "Dataset", "DC.Coverage": "Basic comparison of textual formats", "DC.Contributors": ["Eric W. Brown"], "DC.Language": "en-US", "DC.Date": "2013/09/13 08:19:14.764159 GMT-4", "DC.Rights": "All Rights Reserved", "DC.Publisher": "ZOLL", "Version": 1.0 } JSON <?xml version="1.0" encoding="UTF-8" ?> <test xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en"> <dc:title>Test Data File</dc:title> <dc:description> Simple test to compare INI, JSON, XML, and YAML. </dc:description> <dc:creator>Eric W. Brown</dc:creator> <dc:identifier>1</dc:identifier> <subject> <dc:subject>Test</dc:subject> <dc:subject>INI</dc:subject> <dc:subject>JSON</dc:subject> <dc:subject>XML</dc:subject> <dc:subject>YAML</dc:subject> <dc:subject>Text</dc:subject> </subject> <dc:type>Dataset</dc:type> <dc:coverage>Basic comparison of textual formats</dc:coverage> <contributors> <dc:contributor>Eric W. Brown</dc:contributor> </contributors> <dc:language>en-US</dc:language> <dc:date>2013/09/13 08:19:14.764159 GMT-4</dc:date> <dc:rights>All Rights Reserved</dc:rights> <dc:publisher>ZOLL</dc:publisher> <version>1.0</version> </test> XML DC: Title: Test Data File Description: Simple test to compare INI, JSON, XML, and YAML. Creator: Eric W. Brown Identifier: 1 Subject: - Test - INI - JSON - XML - YAML - Text Type: Dataset Coverage: Basic comparison of textual formats Contributors: - Eric W. Brown Language: en-US Date: 2013/09/13 08:19:14.764159 GMT-4 Rights: All Rights Reserved Publisher: ZOLL Version: 1.0 YAML Monday, September 23, 13
  14. 14. Read - Parse - Write & Size Comparisons (naïve & unscientific) % ./testINI.py 10.1204838753 % ./testJSON.py 8.89217090607 % ./testXML.py 9.28052902222 % ./testYAML.py 9.27972102165 % wc -c test.* 500 test.ini 333 test.ini.gz 490 test.json 337 test.json.gz 889 test.xml 462 test.xml.gz 627 test.yaml 331 test.yaml.gz 3969 total Monday, September 23, 13
  15. 15. Flavors • A handful of popular options: • SOAP • XML-RPC • JSON-RPC • REST • REST is quickly becoming the most popular Monday, September 23, 13
  16. 16. Why REST? Request: POST /GetEvent HTTP/1.1 Host: www.example.org Date: Wed, 31 Aug 2011 12:23:00 GMT Content-Type: application/soap+xml; charset=utf-8 Content-Length: 413 SOAPAction: "http://www.w3.org/2003/05/soap-envelope" <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:ev="http://www.example.org/events"> <soap:Header> </soap:Header> <soap:Body> <ev:GetEvent xmlns:ev="http://www.example.org/GetEvent"> <ev:EventNumber>23</ev:EventNumber> </ev:GetEvent> </soap:Body> </soap:Envelope> Response: HTTP/1.0 200 OK Date: Wed, 31 Aug 2011 12:23:05 GMT Content-Type: application/soap+xml; charset=utf-8 Content-Length: 493 Server: Spiffy SOAP Server SOAPAction: "http://www.w3.org/2003/05/soap-envelope" <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:ev="http://www.example.org/events"> <soap:Header> <ev:Date>2011-09-31T12:23:05-00:00</ev:Date> </soap:Header> <soap:Body> <ev:Event> <ev:Name>Saugus.net Ghost Story Contest Deadline</ev:Name> <ev:Date>October 22, 2011</ev:Date> <ev:Time>11:59:59 PM</ev:Time> </ev:Event> </soap:Body> </soap:Envelope> Fault: HTTP/1.0 200 OK Date: Wed, 31 Aug 2011 12:23:05 GMT Content-Type: application/soap+xml; charset=utf-8 Content-Length: 536 SOAPRequest: POST /GetEvent HTTP/1.1 Host: www.example.org Date: Wed, 31 Aug 2011 12:23:00 GMT Content-Type: application/xml; charset=utf-8 Content-Length: 177 <?xml version="1.0"?> <methodCall> <methodName>example.getEvent</methodName> <params> <param> <value><int>23</int></value> </param> </params> </methodCall> Response: HTTP/1.0 200 OK Date: Wed, 31 Aug 2011 12:23:02 GMT Content-Type: application/xml; charset=utf-8 Content-Length: 531 Server: Spiffy XMLRPC Server <?xml version="1.0"?> <methodResponse> <params> <param> <struct> <member> <name>Name</name> <value><string>Saugus.net Ghost Story Contest Deadline</string></value> </member> <member> <name>Date</name> <value><string>October 22, 2011</string></value> </member> <member> <name>Time</name> <value><string>11:59:59 PM</string></value> </member> </struct> </param> </params> </methodResponse> Fault: HTTP/1.0 200 OK XML-RPC Request: POST /events HTTP/1.1 Host: www.example.org Date: Wed, 31 Aug 2011 12:23:00 GMT Content-Type: application/json; charset=utf-8 Content-Length: 50 { "method":"GetEvent", "params":[23], "id":1 } Response: HTTP/1.0 200 OK Date: Wed, 31 Aug 2011 12:23:02 GMT Content-Type: application/json; charset=utf-8 Content-Length: 158 Server: Spiffy JSONRPC Server { "result":{ "Name":"Saugus.net Ghost Story Contest Deadline", "Date":"October 22, 2011", "Time":"11:59:59 PM" }, "error":null, "id":1 } Fault: HTTP/1.0 200 OK Date: Wed, 31 Aug 2011 12:23:02 GMT Content-Type: application/json; charset=utf-8 Content-Length: 93 Server: Spiffy JSONRPC Server { "result":null, "error":{ "fault":5, "reason":"No such event." }, "id":1 } JSON-RPC Request: GET /GetEvent/23 HTTP/1.1 Host: www.example.org Date: Wed, 31 Aug 2011 12:23:00 GMT Accept: application/json Response: HTTP/1.0 200 OK Date: Wed, 31 Aug 2011 12:23:01 GMT Content-Type: application/json; charset=utf-8 Content-Length: 108 Last-Modified: Tue, 30 Aug 2011 1:00:00 GMT Server: Spiffy REST Server { "Name":"Saugus.net Ghost Story Contest Deadline", "Date":"October 22, 2011", "Time":"11:59:59 PM" } Fault: HTTP/1.0 404 NOTFOUND Date: Wed, 31 Aug 2011 12:23:01 GMT Content-Type: application/json; charset=utf-8 Content-Length: 46 Server: Spiffy REST Server { "fault":5, "reason":"No such event." } REST Keeps Going! Keeps Going! Monday, September 23, 13
  17. 17. Streaming • Chunking is good for large uploads or downloads • Not sufficient for two-way communications • Request / Response cycle has a lot of overhead • WebSockets solve this problem Monday, September 23, 13
  18. 18. Discovery • mDNS • also called Bonjour, Avahi, Rendevous, & Zeroconf • DNS • NIS • hosts file Monday, September 23, 13
  19. 19. Tools • One of the beauties of following standards: other people write the tools • A Web service call can be made via a browser • Firefox, Chrome, Safari, & Opera feature great tools • cURL is freely available for Linux, Mac, and MS-Win Monday, September 23, 13
  20. 20. Wrap-Up • Following standards is good • One benefits from the work of others • Others can more easily use your products Monday, September 23, 13
  21. 21. References • http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html • http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html • http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html • http://www.w3.org/Addressing/ • http://json.org/ Monday, September 23, 13

×