Giter VIP home page Giter VIP logo

fresh's Introduction

Fresh

Fresh is an attempt to create a simple, reliable and flexible WebSocket client built atop the Mint ecosystem ๐ŸŒฑ

Test Status Coverage Status Hex

Why Fresh?

Discover the reasons behind choosing Fresh over existing libraries, summed up in three key aspects:

  • Simplicity
  • Resilience
  • Control

Simplicity

Fresh is designed with simplicity in mind, offering a user-friendly API that includes clear examples and comprehensive documentation.

Resilience

Fresh drew significant inspiration from Redix, particularly in terms of resilience. By default, Fresh promptly re-establishing the connection when the server terminates the connection or encounters any connectivity issues. When used alongside Supervisor, Fresh delivers exceptional reliability.

Control

With Fresh, you gain extensive control over the flow of WebSocket connections, including control over resilience. You can manage scenarios requiring reconnection, identify those that should be ignored, specify when to gracefully terminate a connection, and even instruct Supervisor to restart your process as needed. Additionally, Fresh allows you to leverage custom Mint.WebSocket options, transport layer options, custom headers, and more, providing you with the flexibility you require.

Installation

Package can be installed by adding fresh to your list of dependencies in mix.exs:

defp deps do
  [
    {:fresh, "~> 0.4.4"}
  ]
end

Compatibility

This library is well-tested with the following versions of Elixir and Erlang/OTP:

  • Elixir 1.14 or newer
  • Erlang/OTP 25 or newer

While it may also work with older versions, we strongly recommend using the specified minimum versions for the best experience.

Example

Below is an example of a WebSocket client that handles incoming frames to implement a simple counter:

It is worth mentioning that this example module contains approximately 15 lines of code.

defmodule EchoWebSocket do
  use Fresh

  def handle_connect(_status, _headers, _state) do
    IO.puts("Start counting from 0")
    {:reply, {:text, "1"}, 0}
  end

  def handle_in({:text, number}, _state) do
    number = String.to_integer(number)

    IO.puts("Number: #{number}")
    {:reply, {:text, "#{number + 1}"}, number}
  end
end

You can find more examples inside the examples/ folder.

Documentation

For in-depth information and a detailed API reference, please consult the HexDocs.

License

Fresh is licensed under the MIT license.

fresh's People

Contributors

bunopnu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fresh's Issues

Handle non-existing path

The following code:

defmodule Example do
  use Fresh

  def start_link() do
    __MODULE__.start_link(
      uri: "wss://ws.example.com",
      # ...
    )
  end
end

is currently not working because of a bug inside handling path.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.