{"id":26320923,"url":"https://github.com/gbaeke/websockets","last_synced_at":"2026-05-17T06:39:43.776Z","repository":{"id":280286861,"uuid":"941476718","full_name":"gbaeke/websockets","owner":"gbaeke","description":"Websockets sample with Azure API Managament","archived":false,"fork":false,"pushed_at":"2025-03-02T13:45:30.000Z","size":185,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T14:31:10.439Z","etag":null,"topics":["apim","bicep","python","websockets"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gbaeke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-02T11:41:37.000Z","updated_at":"2025-03-02T13:45:33.000Z","dependencies_parsed_at":"2025-03-02T14:41:21.759Z","dependency_job_id":null,"html_url":"https://github.com/gbaeke/websockets","commit_stats":null,"previous_names":["gbaeke/websockets"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbaeke%2Fwebsockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbaeke%2Fwebsockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbaeke%2Fwebsockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbaeke%2Fwebsockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbaeke","download_url":"https://codeload.github.com/gbaeke/websockets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243754095,"owners_count":20342543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apim","bicep","python","websockets"],"created_at":"2025-03-15T16:15:36.743Z","updated_at":"2025-10-26T11:03:18.734Z","avatar_url":"https://github.com/gbaeke.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python WebSocket Server for APIM Testing\n\nThis is a Python implementation of a WebSocket server that can be used to test Azure API Management (APIM) WebSocket capabilities. The server provides both REST API endpoints and WebSocket communication.\n\n## Quickstart\n\n- Clone the repository\n- Create a virtual environment and install dependencies\n- Run the client and server with `npm run dev-full`\n- Start ngrok with `ngrok http 5001` (install ngrok first)\n\nThis starts the client and server locally. The server is available via the ngrok URL to the outside world.\n\nNow deploy APIM. You need an Azure subscription.\n\n- Go the the `deploy' folder\n- Modify apim.parameters.json:\n  - Change the wsBackendUrl to `wss://\u003cngrok-url\u003e/socket.io/`\n  - Change the httpBackendUrl to `https://\u003cngrok-url\u003e`\n- Run `./deploy-apim.sh`\n\nEnsure that `client/src/App.js` is configured to use the APIM instance.\n\n```javascript\n// API Management endpoints\nconst APIM_HTTP_ENDPOINT = 'https://apim-realtime-dashboard.azure-api.net/dashboard';\nconst APIM_WS_ENDPOINT = 'wss://apim-realtime-dashboard.azure-api.net/dashboard-ws';\n\nconst useApim = true;\n```\nReplace the https and wss endpoints with the APIM endpoint.\n\nIf you want to test the endpoints with `api-requests.http` then set the @baseUrl to the same APIM endpoint for the REST API.\n\n## Features\n\n- WebSocket server that handles client connections\n- REST API endpoints for creating and retrieving updates\n- Automatic broadcasting of updates to all connected WebSocket clients\n- Health check endpoint\n- CORS support\n- OpenAPI documentation\n- Robust error handling for WebSocket connections\n\n## Prerequisites\n\n- Python 3.7 or higher\n- pip (Python package manager)\n\n## Installation\n\n1. Install the required dependencies:\n\n```bash\npip install -r requirements.txt\n```\n\n## Usage\n\n### Running the Server\n\n```bash\npython server.py\n```\n\nThe server will start on port 5001 by default. If that port is already in use, it will automatically try the next port.\n\n### API Endpoints\n\n- `GET /api/updates` - Get all updates\n- `POST /api/update` - Create a new update\n- `GET /health` - Health check endpoint\n- `GET /docs` - OpenAPI documentation (Swagger UI)\n- `GET /openapi.yaml` - OpenAPI specification\n\n### WebSocket Endpoints\n\nThe server provides multiple WebSocket endpoints for flexibility:\n\n- Primary endpoint: `ws://localhost:5001/socket.io/`\n- Alternative endpoint: `ws://localhost:5001/ws/any-path-here`\n\nBoth endpoints provide the same functionality, but the alternative endpoint allows any path after `/ws/`, which can be useful for testing different routing configurations in APIM.\n\n## Client Options\n\n### 1. HTML WebSocket Client\n\nA simple HTML-based WebSocket client is included for testing in the browser:\n\n1. Open the `websocket-test-client.html` file in your browser\n2. The client will automatically connect to `ws://localhost:5001/socket.io/`\n3. You can send messages, heartbeats, and create updates from the UI\n\n### 2. React WebSocket Client\n\nClient is in `client/src`. Run the client with `npm run dev-full`.\n\n## Testing with APIM\n\nTo test your APIM instance with this server:\n\n1. Start the server locally:\n   ```bash\n   python server.py\n   ```\n\n2. Configure your APIM instance to proxy WebSocket connections to your local server.\n   - You may need to use a tool like ngrok to expose your local server to the internet.\n   - Example ngrok command: `ngrok http 5001`\n\n3. Connect the client to your APIM instance:\n   \n   Configure the client to connect to your APIM instance.\n\n## WebSocket Message Format\n\n### Client to Server (Heartbeat)\n\n```json\n{\n  \"type\": \"heartbeat\",\n  \"timestamp\": 1621234567890\n}\n```\n\n### Server to Client (Initial Updates)\n\n```json\n{\n  \"type\": \"initial-updates\",\n  \"data\": [\n    {\n      \"id\": 1621234567890,\n      \"message\": \"System is running normally\",\n      \"type\": \"info\",\n      \"title\": \"System Status\",\n      \"timestamp\": \"2023-07-01T12:00:00.000Z\"\n    }\n  ]\n}\n```\n\n### Server to Client (New Update)\n\n```json\n{\n  \"type\": \"new-update\",\n  \"data\": {\n    \"id\": 1621234567890,\n    \"message\": \"System is running normally\",\n    \"type\": \"info\",\n    \"title\": \"System Status\",\n    \"timestamp\": \"2023-07-01T12:00:00.000Z\"\n  }\n}\n```\n\n## Troubleshooting\n\n- If you see connection errors, check that your APIM instance is properly configured for WebSockets.\n- Ensure that your APIM policies allow WebSocket upgrade requests.\n- Check that the WebSocket protocol is enabled in your APIM instance.\n- Verify that your backend service (this server) is accessible from your APIM instance.\n- If using the React client, make sure you've replaced the Socket.IO client with the WebSocket client.\n- If you're seeing errors with Socket.IO clients, use one of the native WebSocket clients provided. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbaeke%2Fwebsockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbaeke%2Fwebsockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbaeke%2Fwebsockets/lists"}