Modern Petstore API supports multiple API protocols and specifications, making it the most comprehensive reference implementation available. Choose the protocol that best fits your use case.
Quick Protocol Selection#
| Protocol | Best For | Communication Pattern | Complexity |
|---|
| REST | Standard CRUD operations | Request/Response | Low |
| SSE | Real-time streaming, AI responses | Server → Client (unidirectional) | Low |
| WebSocket | Bidirectional real-time communication | Client ↔ Server (full-duplex) | Medium |
| Socket.IO | Real-time with automatic fallback | Client ↔ Server (with fallback) | Medium |
| MQTT | IoT devices, low-bandwidth scenarios | Publish/Subscribe | Medium |
| Webhooks | Event-driven notifications | Server → Client (HTTP callbacks) | Low |
| Callbacks | Async operation status | Server → Client (dynamic URLs) | Medium |
| GraphQL | Flexible data queries | Request/Response | Medium |
| gRPC | High-performance microservices | Request/Response (binary) | High |
| MCP | AI assistant integration | Request/Response | Medium |
Protocol Details#
1. REST API (HTTPS)#
The foundation - Standard HTTP-based API following RESTful principles.Base URL: https://api.petstoreapi.com/v1Standard CRUD operations (Create, Read, Update, Delete)
Resource-oriented operations
Stateful client-server communication
When you need caching (HTTP cache headers)
✅ Pure RESTful design (proper HTTP methods, status codes)
✅ Resource-oriented URLs (/pets, /users, /orders)
✅ Collection wrappers with pagination
✅ RFC 9457 error responses
✅ IETF rate limiting headers
2. Server-Sent Events (SSE)#
Real-time streaming - Server pushes data to client over HTTP.Endpoint: https://api.petstoreapi.com/v1/chat/completions (with stream: true)Real-time updates from server to client
AI chat streaming responses
When you only need server → client communication
✅ Built on HTTP (no new infrastructure needed)
✅ Automatic reconnection handling
✅ Text-based, easy to debug
✅ One-way communication (server → client)
3. WebSocket#
Full-duplex communication - Persistent connection for bidirectional real-time messaging.Endpoint: wss://api.petstoreapi.com/v1/ws/chatReal-time bidirectional communication
Customer support chat systems
Collaborative applications
Low-latency updates required
✅ Full-duplex (send and receive simultaneously)
✅ Binary and text data support
4. Socket.IO#
WebSocket with fallbacks - Real-time communication with automatic fallback.Endpoint: wss://api.petstoreapi.comReal-time features that must work everywhere
Need automatic fallback (polling) when WebSocket unavailable
Building customer support chat
Need room-based messaging
✅ Automatic fallback to long-polling
5. MQTT (Message Queuing Telemetry Transport)#
Lightweight IoT protocol - Publish/subscribe for resource-constrained devices.Endpoint: mqtts://mqtt.petstoreapi.com:8883Low-bandwidth, unreliable networks
Many devices publishing data
✅ Extremely lightweight (small packet overhead)
✅ Publish/Subscribe pattern
✅ QoS levels (guaranteed delivery)
✅ Works on unreliable networks
6. Webhooks#
Event-driven HTTP callbacks - Server pushes events to your endpoints.Real-time notifications for events
Pet adoption notifications
✅ Server initiates the request
✅ Your endpoint receives events
✅ HMAC signature verification
7. GraphQL#
Flexible query language - Request exactly the data you need.Endpoint: https://api.petstoreapi.com/v1/graphqlComplex, nested data requirements
Mobile applications (reduce payload size)
Multiple resources in single request
Flexible, self-documenting API
✅ Request exactly what you need
✅ Single request for multiple resources
✅ Introspection (self-documenting)
8. gRPC#
High-performance RPC - Binary protocol for microservices.High-performance requirements
Microservice-to-microservice communication
Strongly typed contracts needed
Low latency, high throughput
✅ Binary serialization (Protocol Buffers)
✅ Strong typing with .proto files
✅ Built-in code generation
9. MCP (Model Context Protocol)#
AI assistant integration - Connect Claude Desktop and other AI assistants.Building AI-powered tools
Claude Desktop integration
AI assistant needs to query your data
Context-aware AI interactions
✅ Standard protocol for AI tools
✅ Resource and prompt definitions
✅ Native Claude Desktop support
✅ Context-aware responses
{
"name": "petstore-mcp-server",
"command": "node",
"args": ["dist/index.js"],
"env": {
"PETSTORE_API_KEY": "your_api_key",
"PETSTORE_API_BASE": "https://api.petstoreapi.com/v1"
}
}
Protocol Comparison#
When to Use Each Protocol#
┌─────────────────────────────────────────────────────────────────┐
│ Choose Your Protocol │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Need standard CRUD operations? │
│ → Use REST │
│ │
│ Need real-time updates from server? │
│ → Use SSE (one-way) or WebSocket (two-way) │
│ │
│ Building chat/collaboration? │
│ → Use WebSocket or Socket.IO │
│ │
│ IoT devices or constrained networks? │
│ → Use MQTT │
│ │
│ Need event notifications? │
│ → Use Webhooks │
│ │
│ Complex, flexible data queries? │
│ → Use GraphQL │
│ │
│ High-performance microservices? │
│ → Use gRPC │
│ │
│ AI assistant integration? │
│ → Use MCP │
│ │
└─────────────────────────────────────────────────────────────────┘
| Protocol | Latency | Throughput | Overhead | Scalability |
|---|
| REST | Medium | Medium | High | Excellent |
| SSE | Low | Medium | Low | Good |
| WebSocket | Very Low | High | Very Low | Good |
| Socket.IO | Low | High | Low | Good |
| MQTT | Low | Medium | Very Low | Excellent |
| GraphQL | Medium | Medium | Medium | Good |
| gRPC | Very Low | Very High | Very Low | Excellent |
Getting Started#
For Beginners#
1.
Start with REST - It's the most common and well-documented
For Specific Use Cases#
Web Applications: REST + SSE/WebSocket
Mobile Apps: REST + GraphQL
Specifications#
OpenAPI 3.2 (REST, SSE, Webhooks): JSON | YAML AsyncAPI 3.0 (WebSocket, MQTT, Kafka): JSON | YAML
Modified at 2026-01-06 09:45:29