This document provides an introduction to web services, explaining what they are, how they work using standard technologies like HTTP, URLs, JSON and XML, different flavors like SOAP, XML-RPC and REST, and tools for working with web services. It discusses how web services allow applications to communicate over the web through request-response interactions, with REST emerging as the most popular style of web service.
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. 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. 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. How Do They Work?
• A suite of standard technologies:
• HTTP
• URL
• JSON, XML, YAML, etc.
• DNS
Monday, September 23, 13
6. HTTP
• Request
• URL
• Method
• Headers
• Payload
• Response
• Status Code
• Headers
• Payload
• HTTP is stateless!
Monday, September 23, 13
8. HTTP Methods
• Most Common
•GET
•POST
•PUT
•DELETE
• Less Used
•HEAD
•OPTIONS
•CONNECT
•TRACE
•PATCH
Monday, September 23, 13
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. 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. 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. 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. 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
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. 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. 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. Discovery
• mDNS
• also called Bonjour, Avahi,
Rendevous, & Zeroconf
• DNS
• NIS
• hosts file
Monday, September 23, 13
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. Wrap-Up
• Following standards is good
• One benefits from the work of
others
• Others can more easily use
your products
Monday, September 23, 13