{"id":18383768,"url":"https://github.com/elixir-mint/mint_web_socket","last_synced_at":"2025-05-15T15:05:30.066Z","repository":{"id":43008929,"uuid":"365337932","full_name":"elixir-mint/mint_web_socket","owner":"elixir-mint","description":"HTTP/1 and HTTP/2 WebSocket support for Mint 🌱","archived":false,"fork":false,"pushed_at":"2025-01-26T16:00:41.000Z","size":4117,"stargazers_count":131,"open_issues_count":1,"forks_count":14,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-31T20:05:28.752Z","etag":null,"topics":["elixir-lang","http1","http2","mint","websocket"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/mint_web_socket","language":"Elixir","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/elixir-mint.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":"2021-05-07T19:47:14.000Z","updated_at":"2025-03-06T04:51:09.000Z","dependencies_parsed_at":"2023-12-19T01:03:51.623Z","dependency_job_id":"e594a2c9-cec6-482d-b332-6a6876297219","html_url":"https://github.com/elixir-mint/mint_web_socket","commit_stats":{"total_commits":122,"total_committers":9,"mean_commits":"13.555555555555555","dds":"0.11475409836065575","last_synced_commit":"7e298781c7aa9525d63c784d78f6e62ea51825ea"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mint%2Fmint_web_socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mint%2Fmint_web_socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mint%2Fmint_web_socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mint%2Fmint_web_socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-mint","download_url":"https://codeload.github.com/elixir-mint/mint_web_socket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247730068,"owners_count":20986404,"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":["elixir-lang","http1","http2","mint","websocket"],"created_at":"2024-11-06T01:12:26.743Z","updated_at":"2025-04-07T21:09:15.864Z","avatar_url":"https://github.com/elixir-mint.png","language":"Elixir","readme":"# Mint.WebSocket\n\n[![CI][ci-badge]][actions]\n[![Coverage Status][coverage-badge]][coverage]\n[![hex.pm version][hex-version-badge]][hex-package]\n[![hex.pm license][hex-licence-badge]][licence]\n[![Last Updated][last-updated-badge]][commits]\n\nHTTP/1 and HTTP/2 WebSocket support for Mint 🌱\n\n## Usage\n\n`Mint.WebSocket` works together with `Mint.HTTP` API. For example,\nthis snippet shows sending and receiving a text frame of \"hello world\" to a\nWebSocket server which echos our frames:\n\n```elixir\n# bootstrap\n{:ok, conn} = Mint.HTTP.connect(:http, \"echo\", 9000)\n\n{:ok, conn, ref} = Mint.WebSocket.upgrade(:ws, conn, \"/\", [])\n\nhttp_get_message = receive(do: (message -\u003e message))\n{:ok, conn, [{:status, ^ref, status}, {:headers, ^ref, resp_headers}, {:done, ^ref}]} =\n  Mint.WebSocket.stream(conn, http_get_message)\n\n{:ok, conn, websocket} = Mint.WebSocket.new(conn, ref, status, resp_headers)\n\n# send the hello world frame\n{:ok, websocket, data} = Mint.WebSocket.encode(websocket, {:text, \"hello world\"})\n{:ok, conn} = Mint.WebSocket.stream_request_body(conn, ref, data)\n\n# receive the hello world reply frame\nhello_world_echo_message = receive(do: (message -\u003e message))\n{:ok, conn, [{:data, ^ref, data}]} = Mint.WebSocket.stream(conn, hello_world_echo_message)\n{:ok, websocket, [{:text, \"hello world\"}]} = Mint.WebSocket.decode(websocket, data)\n```\n\nCheck out some [examples](./examples) and the online [documentation][hex-docs].\n\n## Functional WebSockets\n\nMint.WebSocket (like Mint) takes a _functional_ approach.\nOther WebSocket implementations like\n[`:gun`][gun] / [`:websocket_client`][websocket-client] /\n[`Socket`][socket] / [`WebSockex`][websockex] work by spawning and\npassing messages among processes. This is a very convenient interface in\nErlang and Elixir but it does not allow the author much control over\nthe WebSocket connection.\n\nInstead `Mint.WebSocket` is process-less: the entire HTTP and WebSocket\nstates are kept in immutable data structures. When you implement a WebSocket\nclient with `Mint.WebSocket`, runtime behavior and process architecture\nare up to you: you decide how to handle things like reconnection and failures.\n\nFor a practical introduction, check out Mint's [usage documentation][mint-usage].\n\n## Spec conformance\n\nThis library aims to follow [RFC6455][rfc6455] and [RFC8441][rfc8441] as\nclosely as possible and uses the [Autobahn|Testsuite][autobahn] to check\nconformance with every run of tests/CI. The auto-generated report produced\nby the Autobahn|Testsuite is uploaded on each push to main.\n\nSee the report here: https://elixir-mint.github.io/mint_web_socket/\n\n## HTTP/2 Support\n\nHTTP/2 WebSockets are not a built-in feature of HTTP/2. In the current\nlandscape, very few server libraries support the RFC8441's extended CONNECT\nmethod which bootstraps WebSockets.\n\nIf `Mint.WebSocket.upgrade/4` returns\n\n```elixir\n{:error, conn, %Mint.WebSocketError{reason: :extended_connect_disabled}}\n```\n\nThen the server does not support HTTP/2 WebSockets or does not have them\nenabled.\n\n## Development workflow\n\nContributions are very welcome!\n\nIf you're interested in developing `Mint.WebSocket`, you'll need docker-compose\nto run the fuzzing test suite. The `docker-compose.yml` sets up an Elixir\ncontainer, a simple websocket echo server, and the Autobahn|Testsuite fuzzing\nserver.\n\nIn host:\n\n```sh\ndocker-compose up -d\ndocker-compose exec app bash\n```\n\nIn app:\n\n```sh\nmix deps.get\nmix test\niex -S mix\n```\n\n[ci-badge]: https://github.com/elixir-mint/mint_web_socket/workflows/CI/badge.svg\n[actions]: https://github.com/elixir-mint/mint_web_socket/actions/workflows/ci.yml\n[coverage]: https://coveralls.io/github/elixir-mint/mint_web_socket\n[coverage-badge]: https://coveralls.io/repos/github/elixir-mint/mint_web_socket/badge.svg\n[hex-version-badge]: https://img.shields.io/hexpm/v/mint_web_socket.svg\n[hex-licence-badge]: https://img.shields.io/hexpm/l/mint_web_socket.svg\n[hex-package]: https://hex.pm/packages/mint_web_socket\n[licence]: https://github.com/elixir-mint/mint_web_socket/blob/main/LICENSE\n[last-updated-badge]: https://img.shields.io/github/last-commit/elixir-mint/mint_web_socket.svg\n[commits]: https://github.com/elixir-mint/mint_web_socket/commits/main\n\n[hex-docs]: https://hexdocs.pm/mint_web_socket/Mint.WebSocket.html\n\n[gun]: https://github.com/ninenines/gun\n[websocket-client]: https://github.com/jeremyong/websocket_client\n[socket]: https://github.com/meh/elixir-socket\n[websockex]: https://github.com/Azolo/websockex\n[mint-usage]: https://github.com/elixir-mint/mint#usage\n\n[rfc6455]: https://datatracker.ietf.org/doc/html/rfc6455\n[rfc8441]: https://datatracker.ietf.org/doc/html/rfc8441\n[autobahn]: https://github.com/crossbario/autobahn-testsuite\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-mint%2Fmint_web_socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-mint%2Fmint_web_socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-mint%2Fmint_web_socket/lists"}