←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Notes

Web Connectivity: SOAP vs. REST, HTTP Restful & WebSockets

Study material and explanations for Unit 3

Web Connectivity: SOAP vs. REST, HTTP Restful, and WebSockets

Introduction: Web Services in the World of IoT

When an IoT device needs to talk to a mobile app or a cloud server (for example, letting you turn on a room AC using your phone), it uses a Web Service Architecture.

In the past, web services relied heavily on SOAP (Simple Object Access Protocol). But because IoT microcontrollers have very little RAM, small batteries, and low bandwidth, the tech industry quickly moved to REST and WebSockets.


1. SOAP vs. REST: Why REST Won the IoT Revolution

SOAP vs. REST Architectural Styles
SOAP (Simple Object Access Protocol)
Strict, heavy XML envelopes, high RAM & CPU usage. Very poor fit for small microcontrollers.
REST (Representational State Transfer)
Flexible, lightweight JSON messages, uses standard HTTP verbs. Ideal for IoT devices and mobile apps.

Detailed Comparison Table for DAVV Exams:

Parameter SOAP REST
Type Formal, rigid Protocol with strict XML rules Flexible Architectural Style based on standard web rules
Data Format Exclusively XML (Heavy, complex tags) Lightweight JSON, Plaintext, or Binary
Payload Size Extremely Heavy: XML tags add 500+ bytes of unnecessary text Lightweight: Short JSON format saves mobile data and battery
CPU & Memory Requires heavy RAM and processing to parse XML trees Low CPU usage; microcontrollers parse JSON very quickly
Transport Can run over HTTP, SMTP, TCP Primarily uses standard HTTP / HTTPS
Caching Hard to cache Easily cached by standard web browsers and gateways
Fit for IoT Very Poor (Overwhelms tiny microcontrollers) Excellent (Industry standard for device-to-cloud APIs)

2. HTTP RESTful Architecture for IoT

In a RESTful IoT architecture, every sensor, actuator, or setting is treated as a Resource with its own unique URL address (called a URI):

  • Example URI for a smart AC: https://api.myhome.com/devices/ac_unit/temperature

Standard REST Verbs in IoT:

  1. GET (Read Sensor Data):
    • Request: GET /sensors/living_room/humidity
    • Response: 200 OK: {"humidity": 55, "unit": "%"}
  2. POST (Register New Device):
    • Used when a new sensor connects for the first time to register its details with the cloud.
  3. PUT (Update Device State / Actuate):
    • Request: PUT /actuators/water_pump with body {"state": "ON"}
    • Action: Turns on the physical water pump!
  4. DELETE (Remove):
    • Deletes an old sensor record or clears past logs.

Key Rules of REST in IoT:

  • Stateless: The server treats each request as completely independent. The device sends its API security key with every request.
  • Client-Server Separation: The software inside the sensor board is completely independent of the cloud database and user UI.

3. WebSockets: Full-Duplex Real-Time Communication

While REST is great for occasional checks, it is too slow for live, real-time control because the client must constantly poll the server.

The WebSocket Protocol provides continuous, two-way (full-duplex) communication over a single open TCP connection.

WebSocket Handshake and Data Flow
1. Client sends HTTP Request with Upgrade: websocket
➔ 2. Server accepts with 101 Switching Protocols ➔
3. Persistent Open Socket!
Both sides talk freely with tiny 2-byte headers!

Why WebSockets Work So Well in IoT:

  1. Instant Server Push: If a factory sensor detects smoke or overheating, the cloud can send a shutdown command to the actuator in under 2 milliseconds without waiting for the device to ask!
  2. Tiny Header Overhead: After the initial handshake, each message carries only 2 to 10 bytes of header overhead (compared to 500+ bytes in HTTP).
  3. Live Streaming Telemetry: Perfect for real-time dashboards (such as tracking a flying drone, streaming patient heartbeat graphs, or tracking a live ambulance on a map).

💡 DAVV Exam Preparation Tips

5-Mark Question: “Differentiate between SOAP and REST web services. Why is REST preferred in IoT?”

  • SOAP: Heavy XML-based protocol with strict rules; takes too much RAM and battery for microcontrollers to parse.
  • REST: Lightweight architectural style using JSON; very fast and simple for microcontrollers like Arduino and ESP32.
  • Conclusion: REST is preferred in IoT because it saves bandwidth, CPU power, and battery life.

10-Mark Question: “Explain HTTP RESTful architecture for IoT devices with URI and HTTP verb examples (GET, POST, PUT, DELETE). What are WebSockets, and how do they achieve full-duplex real-time communication?”

  • Explain REST principles: Resources, URIs, stateless requests, JSON payloads.
  • Provide clear examples for the 4 HTTP verbs:
    • GET (read temperature)
    • POST (register new device)
    • PUT (turn relay ON/OFF)
    • DELETE (clear device log).
  • Draw the WebSocket handshake diagram (Upgrade: websocket ➔ 101 Switching Protocols).
  • Explain why WebSockets excel in IoT: Tiny 2-byte header overhead and instant bi-directional server push for real-time live data.