0% found this document useful (0 votes)
33 views5 pages

IOT & CC Unit 5 Mid Prep Notes

Uploaded by

tempcnt156
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

IOT & CC Unit 5 Mid Prep Notes

Uploaded by

tempcnt156
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

IOT & CC UNIT 5 MID PREPARATION

6. WAMP Protocol, Session Between Client and Router, Installing WAMP


Autobahn

WAMP Protocol:

• Definition: WAMP (Web Application Messaging Protocol) is a communication


protocol that provides two messaging patterns: Publish & Subscribe and routed
Remote Procedure Calls (RPC). It's designed for real-time application scenarios and is
built on top of WebSocket, although it can work with any other reliable, ordered, and
bidirectional transport protocol.
• Publish & Subscribe: In this pattern, publishers send messages to topics without
knowing which subscribers, if any, will receive the messages. Subscribers express
interest in one or more topics and receive messages that match their interests.
• Remote Procedure Calls (RPC): This pattern allows clients to call functions on
remote peers as if they were local. The router mediates these calls, making sure they
reach the correct target.

Session Between Client and Router:

• Establishing Connection: A client initiates a WAMP session by establishing a


WebSocket connection to a WAMP router. The router is responsible for managing the
connections and routing messages between clients.
• Authentication: Once the connection is established, the client may need to
authenticate with the router. This can be done using various methods like ticket-based,
cookie-based, or challenge-response mechanisms.
• Session Management: After authentication, the session is active. During this time,
the client can subscribe to topics, publish messages, and call remote procedures. The
router ensures that messages are delivered to the appropriate recipients.
• Closing the Session: The session can be closed by either the client or the router. This
typically involves a clean shutdown of the WebSocket connection.

Installing WAMP Autobahn:

• Autobahn Library: Autobahn is a robust implementation of the WAMP protocol


available in multiple programming languages, such as Python, JavaScript, and others.
It helps developers to create WAMP clients and routers.
• Installation in Python:
o Use pip to install Autobahn:

bash
Copy code
pip install autobahn

o Example of a basic WAMP client in Python:

python
Copy code
from autobahn.asyncio.wamp import ApplicationSession,
ApplicationRunner

class MyComponent(ApplicationSession):
async def onJoin(self, details):
print("session attached")

if __name__ == '__main__':
runner = ApplicationRunner(url="ws://localhost:8080/ws",
realm="realm1")
runner.run(MyComponent)

• Installation in JavaScript:
o Use npm to install Autobahn:

bash
Copy code
npm install autobahn

o Example of a basic WAMP client in JavaScript:

javascript
Copy code
var autobahn = require('autobahn');

var connection = new autobahn.Connection({


url: 'ws://localhost:8080/ws',
realm: 'realm1'
});

connection.onopen = function (session) {


console.log("session attached");
};

connection.open();

7. RESTful Web

Overview of RESTful APIs:

• REST (Representational State Transfer): An architectural style for designing


networked applications. RESTful APIs use HTTP requests to perform operations on
resources identified by URLs.
• CRUD Operations: RESTful APIs typically support Create (POST), Read (GET),
Update (PUT), and Delete (DELETE) operations.

Main Elements of RESTful API:

1. Client: The application making the request.


2. Server: The application responding to the request.
3. Resource: The object or data being manipulated.

How RESTful APIs Work:

• HTTP Methods:
o GET: Retrieve data from the server.
o POST: Send data to the server to create a resource.
o PUT: Update an existing resource on the server.
o DELETE: Remove a resource from the server.

HTTP verb CRUD action

POST Create
HTTP verb CRUD action

GET Read

PUT Update

PATCH Update

DELETE Delete

• Endpoint: The URL path to the resource (e.g., /api/users).


• Headers: Provide metadata (e.g., authentication tokens).
• Body: Contains the data being sent in POST and PUT requests.

Design and Architecture Constraints:

• Uniform Interface: Standardizes the way resources are accessed and manipulated,
using HTTP methods and unique URLs.
• Client-Server: Separates concerns, allowing the client and server to evolve
independently.
• Stateless: Each request from client to server must contain all the necessary
information to process the request.
• Cacheable: Responses must explicitly indicate if they are cacheable to improve
performance.
• Layered System: Allows for a layered architecture where different layers can be
added or modified independently.
• Code on Demand (Optional): Servers can send executable code to clients to extend
their functionality.

Benefits of RESTful APIs:

• Simplicity: Easy to understand and use due to reliance on standard HTTP protocols.
• Platform Independence: Can be used across different programming languages and
environments.
• Scalability: Stateless nature supports horizontal scaling by distributing requests
across multiple servers.
• Flexibility: Can handle various data formats like JSON, XML, HTML, etc.
• Security: Uses standard HTTP security mechanisms like OAuth, HTTPS, etc.

Common Challenges:

• Endpoint Consistency: Ensuring consistent and meaningful endpoints.


• API Versioning: Managing different versions of the API without breaking existing
clients.
• Handling Large Data: Efficiently managing and transmitting large amounts of data.
• Security: Protecting the API from unauthorized access and vulnerabilities.
• Error Handling: Providing clear and informative error messages.

These expanded details should help provide a more comprehensive understanding of the
WAMP protocol, session management, and installation of Autobahn, as well as the
fundamentals and practical aspects of RESTful web services.

You might also like