{"id":28456301,"url":"https://github.com/phoenixframework/websock_adapter","last_synced_at":"2025-06-29T10:32:32.294Z","repository":{"id":62656718,"uuid":"561449776","full_name":"phoenixframework/websock_adapter","owner":"phoenixframework","description":"Implementation of the WebSock specification for servers","archived":false,"fork":false,"pushed_at":"2024-11-12T17:12:59.000Z","size":78,"stargazers_count":38,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-06-06T23:07:33.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phoenixframework.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2022-11-03T18:03:29.000Z","updated_at":"2025-05-28T13:59:19.000Z","dependencies_parsed_at":"2023-10-24T08:45:24.144Z","dependency_job_id":"2c723862-ad77-4028-9e6e-0534453a150f","html_url":"https://github.com/phoenixframework/websock_adapter","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/phoenixframework/websock_adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock_adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock_adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock_adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock_adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phoenixframework","download_url":"https://codeload.github.com/phoenixframework/websock_adapter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock_adapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262578302,"owners_count":23331599,"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":[],"created_at":"2025-06-06T23:07:36.458Z","updated_at":"2025-06-29T10:32:32.286Z","avatar_url":"https://github.com/phoenixframework.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebSockAdapter\n\n[![Build Status](https://github.com/phoenixframework/websock_adapter/workflows/Elixir%20CI/badge.svg)](https://github.com/phoenixframework/websock_adapter/actions)\n[![Docs](https://img.shields.io/badge/api-docs-green.svg?style=flat)](https://hexdocs.pm/websock_adapter)\n[![Hex.pm](https://img.shields.io/hexpm/v/websock_adapter.svg?style=flat\u0026color=blue)](https://hex.pm/packages/websock_adapter)\n\nWebSockAdapter is a library of adapters from common Web Servers to the\n`WebSock` specification. WebSockAdapter currently supports\n[Bandit](https://github.com/mtrudel/bandit) and\n[Cowboy](https://github.com/ninenines/cowboy).\n\nFor details on the `WebSock` specification, consult the\n[WebSock](https://hexdocs.pm/websock) documentation.\n\n## Usage\n\nWebSockAdapter makes it easy to upgrade Plug connections to WebSock connections.\nHere's a simple example:\n\n```elixir\ndefmodule EchoServer do\n  def init(args) do\n    {:ok, []}\n  end\n\n  def handle_in({\"ping\", [opcode: :text]}, state) do\n    {:reply, :ok, {:text, \"pong\"}, state}\n  end\nend\n\ndefmodule MyPlug do\n  use Plug.Router\n\n  plug Plug.Logger\n  plug :match\n  plug :dispatch\n\n  get \"/\" do\n    # Provide the user with some useful instructions to copy \u0026 paste into their inspector\n    send_resp(conn, 200, \"\"\"\n    Use the JavaScript console to interact using websockets\n\n    sock  = new WebSocket(\"ws://localhost:4000/websocket\")\n    sock.addEventListener(\"message\", console.log)\n    sock.addEventListener(\"open\", () =\u003e sock.send(\"ping\"))\n    \"\"\")\n  end\n\n  get \"/websocket\" do\n    conn\n    |\u003e WebSockAdapter.upgrade(EchoServer, [], timeout: 60_000)\n    |\u003e halt()\n  end\n\n  match _ do\n    send_resp(conn, 404, \"not found\")\n  end\nend\n```\n\nThis simple example illustrates many of the useful features of WebSock / WebSockAdapters:\n\n* Implementing a WebSocket server is a single module, and looks \u0026 acts much like\n  a GenServer does\n* It's easy to pass state from the `WebSockAdapter.upgrade/3`\n  call \u0026 have it show up in your WebSock callbacks\n* Upgrades are handled as a plain Plug call. You are able to route requests to\n  your upgrade endpoint using all of the power of the Plug API\n\nIf you're looking for more detail, Benjamin Milde has a [great blog\npost](https://kobrakai.de/kolumne/bare-websockets) that goes a bit deeper than\nthe simple example above.\n\n## Upgrade Validation\n\nSince `0.5.5`, WebSockAdapter validates requests made via\n`WebSockAdapter.upgrade/3` (this was and continues to also be done by the\nunderlying web server, but since the server's validation occurs after the\n`Plug.call/2` lifecycle completes it's difficult to meaningfully handle such\nerrors). This validation examines the request for conformance to the clauses\nlaid out in RFC6455§4.2, as well as RFC8441§5 for HTTP/2 connections. Requests\nwhich do not satisfy the requirements laid out in those specifications will\nresult in a `WebSockAdapter.UpgradeError` being raised, containing\ndetails of the reason for the failure\n\n## Installation\n\nThe websock_adapter package can be installed by adding `websock_adapter` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:websock_adapter, \"~\u003e 0.5\"}\n  ]\nend\n```\n\nDocumentation can be found at \u003chttps://hexdocs.pm/websock_adapter\u003e.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphoenixframework%2Fwebsock_adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphoenixframework%2Fwebsock_adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphoenixframework%2Fwebsock_adapter/lists"}