{"id":22466315,"url":"https://github.com/hummingbird-project/hummingbird-websocket","last_synced_at":"2025-06-17T07:33:53.347Z","repository":{"id":46996253,"uuid":"338594547","full_name":"hummingbird-project/hummingbird-websocket","owner":"hummingbird-project","description":"Websocket upgrade support for Hummingbird","archived":false,"fork":false,"pushed_at":"2024-04-30T09:42:32.000Z","size":241,"stargazers_count":23,"open_issues_count":2,"forks_count":5,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-05-02T02:53:17.412Z","etag":null,"topics":["hummingbird","server","swift","websocket"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hummingbird-project.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":"adam-fowler"}},"created_at":"2021-02-13T14:39:27.000Z","updated_at":"2024-05-09T09:00:47.617Z","dependencies_parsed_at":"2023-02-10T11:01:25.288Z","dependency_job_id":"b6e1eb53-c9fb-4f26-84a4-90cca0e45ddb","html_url":"https://github.com/hummingbird-project/hummingbird-websocket","commit_stats":{"total_commits":62,"total_committers":1,"mean_commits":62.0,"dds":0.0,"last_synced_commit":"8cb4bf546e0215f2b6294e0964d1de4adb496ddd"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummingbird-project%2Fhummingbird-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummingbird-project%2Fhummingbird-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummingbird-project%2Fhummingbird-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummingbird-project%2Fhummingbird-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hummingbird-project","download_url":"https://codeload.github.com/hummingbird-project/hummingbird-websocket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228446406,"owners_count":17921107,"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":["hummingbird","server","swift","websocket"],"created_at":"2024-12-06T10:11:33.619Z","updated_at":"2025-06-17T07:33:53.329Z","avatar_url":"https://github.com/hummingbird-project.png","language":"Swift","funding_links":["https://github.com/sponsors/adam-fowler"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/hummingbird-project/hummingbird/assets/9382567/48de534f-8301-44bd-b117-dfb614909efd\"\u003e\n  \u003cimg src=\"https://github.com/hummingbird-project/hummingbird/assets/9382567/e371ead8-7ca1-43e3-8077-61d8b5eab879\"\u003e\n\u003c/picture\u003e\n\u003c/p\u003e  \n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://swift.org\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/swift-5.10-brightgreen.svg\"/\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/hummingbird-project/hummingbird-websocket/actions?query=workflow%3ACI\"\u003e\n  \u003cimg src=\"https://github.com/hummingbird-project/hummingbird-websocket/actions/workflows/ci.yml/badge.svg?branch=main\"/\u003e\n\u003c/a\u003e\n\u003ca href=\"https://discord.gg/7ME3nZ7mP2\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/chat-discord-brightgreen.svg\"/\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n# Hummingbird Websocket\n\nAdds support for upgrading HTTP1 connections to WebSocket. \n\n## Usage\n\nSetup WebSocket upgrades with a closure that either returns `.upgrade` with response headers and the handler for the WebSocket or a `.dontUpgrade`\n```swift\nlet app = Application(\n    router: router,\n    server: .http1WebSocketUpgrade { request, channel, logger in\n        // upgrade if request path is \"/ws\"\n        guard request.path == \"/ws\" else { return .dontUpgrade }\n        // The upgrade response includes the headers to include in the response and \n        // the WebSocket handler\n        return .upgrade([:]) { inbound, outbound, context in\n            for try await packet in inbound {\n                // send \"Received\" for every packet we receive\n                try await outbound.write(.text(\"Received\"))\n            }\n        }\n    }\n)\napp.runService()\n```\nOr alternatively use a `Router`. Using a router means you can add middleware to process the initial upgrade request before it is handled eg for authenticating the request.\n```swift\nlet wsRouter = Router(context: BasicWebSocketRequestContext.self)\nwsRouter.middlewares.add(BasicAuthenticator())\n// An upgrade only occurs if a WebSocket path is matched\nwsRouter.ws(\"/ws\") { request, context in\n    // allow upgrade\n    .upgrade()\n} onUpgrade: { inbound, outbound, context in\n    for try await packet in inbound {\n        // send \"Received\" for every packet we receive\n        try await outbound.write(.text(\"Received\"))\n    }\n}\nlet app = Application(\n    router: router,\n    server: .http1WebSocketUpgrade(webSocketRouter: wsRouter)\n)\napp.runService()\n```\n\n## Documentation\n\nYou can find documentation for HummingbirdWebSocket [here](https://hummingbird-project.github.io/hummingbird-docs/2.0/documentation/hummingbirdwebsocket). The [hummingbird-examples](https://github.com/hummingbird-project/hummingbird-examples) repository has a number of examples of different uses of the library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhummingbird-project%2Fhummingbird-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhummingbird-project%2Fhummingbird-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhummingbird-project%2Fhummingbird-websocket/lists"}