Jsdr3398

Jsdr3398

Raxx routing doesn't seem to work

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?

# 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

# 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 :sweat_smile:

Thanks in advance! :smiley:

Marked As Solved

crowdhailer

crowdhailer

Creator of Raxx

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

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

Also Liked

Jsdr3398

Jsdr3398

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

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

AstonJ

AstonJ

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

Jsdr3398

Jsdr3398

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

Where Next?

Popular Backend topics Top

DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
dimitarvp
Hey everyone, I resumed work on my Elixir <=> SQLite library (which uses a Rust NIF underneath) and I am in a need of small and we...
New
Kurisu
Hello and happy new year! I would like to buy a Ruby On Rails ebook for learning purpose. What would be the ROR equivalent of “Programm...
New
Ookma-Kyi
I am learning Elixir at the moment but am finding it difficult to learn. The issue is there aren’t any good tutorial sites out there when...
New
Fl4m3Ph03n1x
Background I am trying to get a Github Action working with Windows and Bakeware because I am trying to create a release using it. Howeve...
New
Fl4m3Ph03n1x
Background I am trying to find a cheap and easy way to create New Types in Elixir, and Records seem to be just what I would need. Probl...
New
Fl4m3Ph03n1x
Background I have to queries that return a colossal amount of data on their own. I cannot use Repo.all as doing so would materialize thes...
New
pillaiindu
Currently reading the book “Programming Phoenix LiveView”. At the end of the Chapter 1, I’m trying to solve the guess game. If the user ...
New
Patricia-Mendes13
Hi guys!! I´m studying and got a Full stack course but the course lacked a lot of support and and info to learn as it´s a course after wo...
New
apoorv-2204
Anyone know how to get in golang? I am from elixir background?.
New

Other popular topics Top

axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New