WebSockets Prompts
AI prompts for websockets from the LearnWithHasan AI Coding Building Blocks (Architecture).
Add Real-Time Chat to My App
Start here: the classic WebSocket use case From the WebSockets AI Coding Building Block.
Add a real-time chat feature to my app using WebSockets. Framework: [Express + Socket.io, Django Channels, FastAPI WebSockets, etc.] I want: 1. Users can send messages and see them appear instantly 2. All connected users see new messages in real-time (no page refresh) 3. Show a simple "user is typing..." indicator 4. Handle what happens when someone disconnects Keep it simple: just the core chat functionality. Show me: - The server-side WebSocket setup - The client-side JavaScript to connect and send/receive messages - How messages get broadcast to everyone I'm learning WebSockets for the first time, so explain each part simply.
Stream AI Responses in Real-Time
Build ChatGPT-style streaming into your app From the WebSockets AI Coding Building Block.
I want my app to stream AI responses word-by-word, like ChatGPT does, instead of waiting for the entire response. Framework: [Express, Django, FastAPI, Next.js, etc.] AI Provider: [OpenAI, Anthropic Claude, or describe your setup] I want: 1. User submits a prompt through a text input 2. The AI response appears word by word in real-time (streaming) 3. A "thinking..." indicator while the first token is loading 4. The ability to stop/cancel the stream mid-response Show me: - How to set up streaming from the AI API - How to push each chunk to the browser as it arrives - The frontend JavaScript that displays tokens as they stream in I'm new to streaming and WebSockets, so explain the connection between them simply.
Explain WebSocket Code I Found
Understand existing WebSocket code From the WebSockets AI Coding Building Block.
I have some WebSocket code but I don't fully understand what it's doing. Please explain it to me in simple terms. Here's the code: [paste your WebSocket code here] Please explain: 1. What does this code do? (one sentence summary) 2. Walk through it step by step: what happens when a connection opens? 3. How are messages sent and received? 4. What happens when the connection drops? 5. Are there any common issues or missing pieces I should know about? Use the phone-call analogy: opening a connection = dialing, messages = talking, closing = hanging up. I'm learning WebSockets for the first time, so keep it beginner-friendly.