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

pillaiindu
Cross posting from HashNode. A friend of mine is creating Uber-like app for a small company with 200 to 1000 cars. The app will operate ...
New
IhorYachmenov
Hello. I have an iOS app where needs a proxying website through private server(HTTP / HTTPS proxy), but its idea each time has some trou...
New
s2k
I have this code in a file that’s used to … render templates. require 'erb' require 'ostruct' MISSING_CONFIG_MARKER = :config_key_and_v...
New
bsek43
Hello everyone, I’ve started learning Elixir and Phoenix few months ago and while I mostly grasped Elixir’s functional concepts and Phoe...
New
Fl4m3Ph03n1x
Background I am now trying Gradual type checking, as a consequence I am giving a shot to Gradient. As I see it, this is an alternative to...
New
conradwt
Hi, I’m building an application that will have support for both the web and mobile. At this time, I’m using PhxGenAuth for authenticatio...
New
sona11
In Java, if I try to do.equals() on a null string, a null pointer error is issued. I’m wondering whether I can perform the following if I...
New
sona11
I wrote this code to calculate Fibonacci numbers by specifying the size. The results are correct, however the one thing that concerns me ...
New
harwind
In C, how they are different? char str[] = "xyz"; // statement //and char str[4] = "xyz"; // statement The first, i...
/c
New
Fl4m3Ph03n1x
Background As I often do, I read books to learn and improve myself. I also enjoy teaching and helping others when I can, so this is somet...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
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