
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
Thanks in advance!
Marked As Solved

crowdhailer
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
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

AstonJ
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

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










Other popular topics









Latest in Questions
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim