REST is an architectural style for designing networked applications. Key principles:
Stateless: Each request contains all necessary information; no client context stored on the server.
Resource-based: URLs represent resources (/users/123), not actions (/getUser).
Standard methods: GET, POST, PUT, PATCH, DELETE map to CRUD operations.
Representation: Resources can be represented as JSON, XML, or other formats.
Real-Time Protocols
WebSocket: Full-duplex persistent connection over TCP. Used for chat, live notifications, real-time dashboards.
SSE (Server-Sent Events): Unidirectional server-to-client streaming over HTTP. Simpler than WebSocket; good for live feeds, notifications.
WebRTC: Peer-to-peer real-time communication (audio, video, data). Used for video calls, conferencing.
Modern API Protocols
gRPC: High-performance RPC framework using Protocol Buffers and HTTP/2. Supports streaming, bidirectional communication. Used heavily in microservices.
GraphQL: Query language that lets clients request exactly the data they need. Reduces over-fetching and under-fetching. Single endpoint, complex queries.
Exercise: Your team is building a real-time collaborative document editor (like Google Docs). Which protocols would you use for: a) sending edits between users, b) loading the document from the server, c) notifying users of presence (who is editing). Justify each choice.