http-service-patterns

Build resilient FastAPI services with lifespan handling, WebSocket relays, and SSE streaming.

10|11|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/microsoft/amplifier-bundle-skills --skill http-service-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: http-service-patterns
Source: https://github.com/microsoft/amplifier-bundle-skills/tree/main/skills/http-service-patterns
Command: npx skills add https://github.com/microsoft/amplifier-bundle-skills --skill http-service-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you build reliable HTTP services that need more than basic request handling, including startup and shutdown lifecycle management, background reconciliation loops, WebSocket proxying, and streaming updates to a browser. It is especially useful when services must recover cleanly from stale processes, avoid restart crash-loops, and keep real-time connections working under failure conditions.

Core Features & Use Cases

  • FastAPI lifecycle management: Start and stop background tasks safely using lifespan hooks.
  • WebSocket relay patterns: Proxy browser WebSockets to backend processes with authentication checks and bidirectional message forwarding.
  • SSE event streaming: Stream incremental updates from a file-backed event log to clients.
  • Production hardening: Prevent port binding failures, clean up orphaned processes, and handle startup race conditions.
  • Use Case: Build a web dashboard that monitors long-running jobs, relays terminal sessions, and keeps polling state in the background without manual restarts.

Quick Start

Ask the model to design a FastAPI service using these patterns for your app, including lifespan startup, background polling, WebSocket relay, and SSE streaming.

Frequently Asked Questions about http-service-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage FastAPI lifespan to start and stop background tasks safely?

FastAPI lifespan management uses startup and shutdown hooks to safely initialize background polling loops and clean up orphaned processes. This prevents restart crash-loops and ensures background tasks recover cleanly from stale process states.

How do I proxy a browser WebSocket connection to a backend process in FastAPI?

WebSocket relay patterns in FastAPI proxy browser connections to backend processes by implementing authentication checks before acceptance and forwarding bidirectional messages. This keeps real-time connections working securely under failure conditions.

How do I stream incremental updates to a browser using SSE in FastAPI?

SSE event streaming in FastAPI streams incremental updates to clients by reading from a file-backed event log. This allows browsers to monitor long-running jobs and receive real-time terminal session updates efficiently.

How do I prevent port binding failures and handle startup race conditions in HTTP services?

Production hardening for HTTP services prevents port binding failures and handles startup race conditions by applying startup cleanup routines. This clears orphaned processes before binding, ensuring resilient service restarts without crash-loops.

Do I need FastAPI to use these HTTP service patterns for WebSocket proxying and background polling?

These HTTP service patterns require FastAPI to implement WebSocket proxying, background polling, and SSE streaming. The framework's lifespan hooks and asynchronous routing are essential for maintaining resilient real-time browser connections and background reconciliation loops.