Raxx

From Elixir Wiki
Jump to navigation Jump to search

Raxx[edit]

File:Raxx Logo.png
The Raxx Logo

Raxx is a lightweight web server interface for the Elixir programming language. It provides a simple and flexible way to build web applications and APIs.

Features[edit]

  • Supervisor-based Architecture: Raxx is built on top of Supervisor and GenServer. This architecture ensures fault-tolerance and scalability.
  • Plug Compliant: Raxx follows the Plug specification, allowing developers to leverage the vast ecosystem of Plug middleware.
  • HTTP/2 Support: Raxx fully supports the HTTP/2 protocol, enabling efficient and faster communication between clients and servers.
  • WebSocket Support: Raxx comes with built-in support for WebSocket communication, allowing real-time bidirectional communication between clients and servers.
  • SSE (Server-Sent Events) Support: Raxx provides an easy-to-use API for implementing SSE, enabling server-to-client streaming of events.
  • HTTP/1.x Compatibility: Raxx is compatible with the HTTP/1.x protocol, ensuring seamless integration with existing HTTP libraries and frameworks.

Installation[edit]

To include Raxx in your Elixir project, simply add it as a dependency in your `mix.exs` file:

```elixir defp deps do

 [
   {:raxx, "~> 1.0"}
 ]

end ```

After adding the dependency, fetch and compile the dependency using Mix:

```bash $ mix deps.get ```

Usage[edit]

Using Raxx is straightforward. Start by defining a module that implements the Raxx.Protocol behaviour:

```elixir defmodule MyApp.HTTP do

 @behaviour Raxx.Protocol
 def handle_request(req) do
   case req.method do
     :GET ->
       case req.path do
         "/hello" ->
           {:ok, "200 OK", [{"content-type", "text/plain"}], "Hello, Raxx!"}
         _ ->
           {:ok, "404 Not Found", [], "Page not found."}
       end
     _ ->
       {:ok, "405 Method Not Allowed", [], ""}
   end
 end

end ```

Next, start the server using Raxx.Server with the module as the handler:

```elixir defmodule MyApp.Application do

 use Application
 def start(_type, _args) do
   children = [
     MyApp.HTTP
   ]
   opts = [strategy: :one_for_one, name: MyApp.Supervisor]
   Supervisor.start_link(children, opts)
 end

end ```

Resources[edit]

Learn more about Raxx and its capabilities by exploring these resources: