Web Services
Introduction
This lecture covers the fundamentals of communication over the web, focusing on HTTP, data formats like XML and JSON, and the architecture of Web Services, particularly REST and SOAP.
Internet Protocols
Internet protocols are standardized rules and formats that enable devices to communicate over the internet. They define how data is transmitted, addressed, routed, and received, ensuring reliable and efficient communication between computers and networks. Key examples include HTTP/HTTPS for web traffic, TCP/IP for data transfer and addressing, DNS for domain name resolution, and SMTP for email delivery. These protocols form the foundation of modern internet communication.
Identifying resources on the web
- URI (Uniform Resource Identifier): Identifier for a resource.
- URL (Uniform Resource Locator): Specifies how and where to access a resource.
- URN (Uniform Resource Name): Specifies the name of the resource without the access method.
Example:
http://www.colorado.edu
Here, this is a URL (and thus also a URI).
HTTP – HyperText Transfer Protocol
- Request/Response Protocol.
- Stateless: No client context is stored between requests.
- Clients send requests; servers respond with resources and status codes.
Common HTTP Methods:
Method | Purpose |
---|---|
GET | Retrieve a resource. |
POST | Submit new data. |
PUT | Update/replace a resource. |
DELETE | Remove a resource. |
Common HTTP Status Codes
- 200 OK: Request succeeded.
- 201 Created: New resource created.
- 400 Bad Request: Malformed request.
- 401 Unauthorized: Authentication required.
- 404 Not Found: Resource not found.
- 500 Internal Server Error: Generic server error.
Passing Data to/from the Web Server
XML (Extensible Markup Language)
Structured, hierarchical data format.
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
</bookstore>
JSON (JavaScript Object Notation)
Lightweight and easy-to-read data format.
{
"bookstore": {
"book": [
{
"title": "Everyday Italian",
"author": "Giada De Laurentiis",
"year": "2005",
"price": "30.00"
}
]
}
}
JSON vs XML
Feature | JSON | XML |
---|---|---|
Syntax | Lightweight, JavaScript friendly | Verbose, tag-based |
Speed | Faster for AJAX | Slower parsing |
Readability | Easier for humans | More complex |
Use Cases | APIs, Mobile | Complex structured data |
JSON is generally preferred for modern APIs.
AJAX – Asynchronous JavaScript and XML
- Allows updating parts of a web page without reloading the whole page.
- Backbone of Web 2.0 interactivity.
- AJAX uses XMLHttpRequest or modern
fetch()
APIs.
Web Services
Definition: A framework that allows computers to communicate over the internet.
Components:
- Message Format: JSON, XML, SOAP.
- Request Syntax: URI, HTTP Methods.
- Authentication: Tokens, API Keys.
- Actions: Defined server operations.
- Response Format: JSON or XML.
The complexity is hidden behind an API (Application Programming Interface).
RESTful Web Services
What is REST?
- Representational State Transfer: An architectural style.
- Resources: Everything is a resource identified by a URI.
- Operations: Use HTTP methods (GET, POST, PUT, DELETE).
- Stateless: Each request contains all necessary information.
Characteristics:
- Uniform interface (standard HTTP methods).
- Stateless communication.
- Resource-based URIs.
- Representations in JSON, XML, or HTML.
Advantages:
- Simpler, faster, and scalable.
- Easy to integrate with mobile/web clients.
SOAP Web Services
What is SOAP?
- Simple Object Access Protocol.
- XML-based messaging protocol.
- Strict specifications and high security.
- Heavier and more complex than REST.
Use Cases:
- Enterprise-grade, secure transactions (e.g., banking, government APIs).
Best Practices for Web Services
- Use REST and JSON for lightweight, high-performance web services.
- Secure APIs with authentication mechanisms.
- Validate and sanitize all client inputs.
- Design clear, consistent resource URIs.
Reflection Questions
- What is the difference between a URI and a URL?
- What is the primary difference between REST and SOAP?
- Why is JSON preferred over XML in modern APIs?
- What does it mean that HTTP is stateless?
Summary
- HTTP enables stateless communication over the web.
- Data is passed primarily in JSON or XML formats.
- AJAX enables dynamic updates without page reloads.
- Web Services (REST and SOAP) allow systems to interact over the web.
- REST is the modern standard for lightweight, scalable web APIs.
Disclaimer: Generative AI was used in part to generate these lecture notes.