phoenix
Version, currently 0.2.02 versions
- 0.2.0latestJan 12, 2019
- 0.1.0not indexedJul 28, 2021
github.com/dtcristo/phoenix.cr
Phoenix Channels client for Crystal
26 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
phoenix:
github: dtcristo/phoenix.cr
version: ~> 0.2.0Then run:
shards installshard.yml
- Crystal
0.27.0- License
- MIT
- Author
- David Cristofaro <david@dtcristo.com>
Dependencies
This version declares no dependencies.
Documentation
Generated from the source of the current release. The first visit to a release that has never been documented starts its build.
README
# phoenix.cr
Crystal client for [Phoenix](http://phoenixframework.org/) [Channels](https://hexdocs.pm/phoenix/channels.html), based off the official JavaScript [reference implementation](https://github.com/phoenixframework/phoenix/blob/5ec246543e0950e10eab52aba333b644767c885e/assets/js/phoenix.js).
API documentation available [here](https://dtcristo.github.io/phoenix.cr/).
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
phoenix:
github: dtcristo/phoenix.cr
```
## Usage
The example below shows basic usage; connecting to a socket, joining a channel, binding to an event and sending messages.
```crystal
require "phoenix"
# Create socket and connect to it
socket = Phoenix::Socket.new("http://example.com/socket")
socket.connect
# Initiate a channel, bind to an event and join
channel = socket.channel("topic:subtopic")
channel.on "event" do |payload|
# do stuff with payload
end
channel.join
# Start a loop and send a message down the channel every second
loop do
sleep 1
channel.push("new_msg", JSON::Any.new({"text" => JSON::Any.new("Hello world!")}))
end
```
The Phoenix Channels [docs](https://hexdocs.pm/phoenix/channels.html) provide details on implementing sockets and channels on the server side. The phoenix.cr [docs](https://dtcristo.github.io/phoenix.cr/) detail the client side API available for use in your Crystal application.
## Chat example
[examples/chat.cr](https://github.com/dtcristo/phoenix.cr/blob/master/examples/chat.cr) demonstates an example chat client.
Start the [phoenix-chat](https://github.com/dtcristo/phoenix-chat) server example:
```sh
git clone https://github.com/dtcristo/phoenix-chat
cd phoenix-chat
mix deps.get
mix phx.server
```
Run the chat client:
```sh
crystal examples/chat.cr
```
Follow the prompts to enter your name and chat away.
## TODO
- Add tests
- Implement Presence
- Build larger example application
## Contributors
- [dtcristo](https://github.com/dtcristo) David Cristofaro - creator, maintainer
## Credits
- Thanks [chrismccord](https://github.com/chrismccord) and the [Phoenix team](https://github.com/phoenixframework/phoenix/graphs/contributors) for building an amazing web framework.
Links
This release
- Version
0.2.0- Tagged
- Jan 12, 2019
- Commit
eec287f5d823- Crystal
0.27.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/dtcristo/phoenix.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 2