# Raxx routing doesn't seem to work

**URL:** <https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175>\
**Category:** Backend Questions/Help\
**Tags:** elixir, raxx\
**Created:** [21 January 2021 10:30 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175 "2021-01-21T10:30:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jsdr3398](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@Jsdr3398](https://forum.devtalk.com/u/Jsdr3398)\
**Post date:** [21 January 2021 10:30 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175/1 "2021-01-21T10:30:39Z")

</div>

I’m trying to create a router where everything is in a collection of routes (similar to how I do my routes in expressjs). But it doesn’t seem to work. Can anyone help me out?

```elixir
# routes.ex
defmodule Api.API.Router do
  use Raxx.Router
  alias Api.API.Actions

  def stack(config) do
    Raxx.Stack.new(
      [
        # Add global middleware here.
      ],
      { __MODULE__ , config}
    )
  end

  section([{Raxx.Logger, Raxx.Logger.setup(level: :info)}], [
    {%{path: []}, Actions.RootRoute},
    {%{path: ["users"]}, Actions.Users}
  ])

  section([{Raxx.Logger, Raxx.Logger.setup(level: :debug)}], [
    {_, Actions.NotFound}
  ])
end

```

```elixir
# controllers/users.ex
defmodule Api.API.Actions.Users do
  use Raxx.SimpleServer
  alias Api.API

  @impl Raxx.SimpleServer
  def handle_request(_request = %{method: :GET}, _state) do
    response(:ok)
    |> API.set_json_payload(%{path: "root"})
  end

  def handle_request(_request = %{method: :GET, path: ["test"]}, _state) do
    response(:ok)
    |> API.set_json_payload(%{path: "test"})
  end

  def handle_request(_request = %{method: :GET, path: ["testo"]}, _state) do
    response(:ok)
    |> API.set_json_payload(%{path: "testo"})
  end
end

```

`/users/` is normal and works fine, but I get a not found error when I try to access `/users/test` or `/users/testo` 😅

Thanks in advance! 😃

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [21 January 2021 16:58 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175/3 "2021-01-21T16:58:33Z")

</div>

Going to ping @crowdhailer for you as he’ll be able to give you the best answer being Raxx’s creator 😊 Hopefully he’ll be able to spare a few minutes to help you 😃

---

<div class="post-metadata">

**Author:** ![crowdhailer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/crowdhailer/32/556_2.png) [@crowdhailer](https://forum.devtalk.com/u/crowdhailer)\
**Post date:** [21 January 2021 19:02 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175/4 "2021-01-21T19:02:04Z")

</div>

Your first function head is matching all Gets requests. This is how Elixir does pattern matching,  
Nothing really Raxx specific, apart from the fact it gives you the data structure.

If you don’t specify a path it will match on all, try this instead.

Try

```elixir
 @impl Raxx.SimpleServer
  def handle_request(_request = %{method: :GET: path: []}, _state) do
    response(:ok)
    |> API.set_json_payload(%{path: "root"})
  end

```

---

<div class="post-metadata">

**Author:** ![Jsdr3398](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@Jsdr3398](https://forum.devtalk.com/u/Jsdr3398)\
**Post date:** [21 January 2021 19:46 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175/5 "2021-01-21T19:46:37Z")

</div>

I haven’t got an opportunity to test this yet, but it makes sense now that I think about it. Thank you!

---

<div class="post-metadata">

**Author:** ![Jsdr3398](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@Jsdr3398](https://forum.devtalk.com/u/Jsdr3398)\
**Post date:** [22 January 2021 07:23 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175/6 "2021-01-22T07:23:28Z")

</div>

just tested it and /users/ still works fine while the other routes return a 404 🤔

```elixir
defmodule Api.API.Actions.Users do
  use Raxx.SimpleServer
  alias Api.API

  @impl Raxx.SimpleServer
  def handle_request(_request = %{method: :GET, path: []}, _state) do
    response(:ok)
    |> API.set_json_payload(%{path: "root"})
  end

  def handle_request(_request = %{method: :GET, path: ["test"]}, _state) do
    response(:ok)
    |> API.set_json_payload(%{path: "test"})
  end

  def handle_request(_request = %{method: :GET, path: ["testo"]}, _state) do
    response(:ok)
    |> API.set_json_payload(%{path: "testo"})
  end
end

```

---

<div class="post-metadata">

**Author:** ![crowdhailer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/crowdhailer/32/556_2.png) [@crowdhailer](https://forum.devtalk.com/u/crowdhailer)\
**Post date:** [22 January 2021 08:30 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175/7 "2021-01-22T08:30:32Z")

</div>

Not sure what’s happening, as you don’t have a “users” path in the code you shared.

p.s. I’m not often fast on replying so you might want to try the #raxx slack channel, [https://app.slack.com/client/T03EPRA2X/C56H3TBH8](https://app.slack.com/client/T03EPRA2X/C56H3TBH8)

---

<div class="post-metadata">

**Author:** ![Jsdr3398](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@Jsdr3398](https://forum.devtalk.com/u/Jsdr3398)\
**Post date:** [22 January 2021 08:39 UTC](https://forum.devtalk.com/t/raxx-routing-doesnt-seem-to-work/6175/8 "2021-01-22T08:39:20Z")

</div>

The first code block (routes.ex) has it. Will check out slack though, it’s super confusing tho so it may take a while 😅

Edit: found the issue and added an `_` to the routes array to properly match the path
