RxAssim

RxAssim

Hello Elixir community! I’m excited to announce the first release of Routes, a library that automatically generates JavaScript and TypeScript route helpers from your Phoenix router. It aims to bring the convenience and type safety of Phoenix route helpers to your frontend code.

Why Routes?

Working with Phoenix and modern JavaScript frameworks, I often found myself manually maintaining route paths in the frontend or creating custom solutions to keep frontend routing in sync with Phoenix routes. Routes solves this by:

  • :counterclockwise_arrows_button: Automatically generating route helpers from your Phoenix router
  • :memo: Providing full TypeScript support with type definitions
  • :magnifying_glass_tilted_left: Supporting live reloading during development
  • :bullseye: Handling path parameters and query strings with type safety
  • :flexed_biceps: Ensuring route parameters are correctly typed and validated

Quick Example

# In your Phoenix router
defmodule MyAppWeb.Router do
  use Phoenix.Router
  use Routes

  scope "/" do
    get "/users/:id", UserController, :show, as: :user
  end
end
// In your JavaScript/TypeScript code
import Routes from './routes';

// Type-safe route generation
const url = Routes.path('user.show', { id: 123 });
// => "/users/123"

// With query parameters
const searchUrl = Routes.path('user.index', {
  _query: { search: 'john', filter: 'active' }
});
// => "/users?search=john&filter=active"

Inertia.js Integration

If you’re using Inertia.js, Routes provides a clean way to create type-safe navigation:

<Link
  to="/users/:id"
  params={{ id: 123, _query: { tab: "profile" } }}
>
  View Profile
</Link>

Getting Started

Add to your mix.exs:

def deps do
  [
    {:routes, "~> 0.1.0"}
  ]
end

Configure in config.exs:

config :routes,
  router: MyAppWeb.Router,
  typescript: true,
  routes_path: "assets/js/routes"

Links

https://github.com/assimelha/routes

Feedback Welcome!

This is the initial release, and I’d love to hear your thoughts, suggestions, and use cases. Feel free to open issues on GitHub or contribute to the project.

Happy coding! :tada:

Showing Posts 1 to 3

BartOtten

BartOtten

Hi @RxAssim,

Always nice to see people invest time in the eco system! As for the feedback:

  1. Pardon my question but I fail to see the use case. Where does this fit in? When does a server side path need a sync with client side, which can not be (and afaik is) handled by Phoenix LiveView?*

Edit: answer myself: Inertiajs of course :slight_smile:

—-

  1. The name of the lib is a bit too close to my lib RouteX for my taste to be honest and also in the same valley as libs called ‘framework’ or ‘xml’. I would suggest a more distrinct name.

—-

  1. Maybe this can be a Routex extension? This would solve the naming issue, you can focus on the Typescript part (as processing and live regeneration is taken care of) and all features of Routex will be supported by the Typescript files (alternative routes for instance).

Kind regard,
Author of Routex

RxAssim

RxAssim OP

Hi @BartOtten,

  1. Yes, you could use it with Inertia, Live_svelte, Live_vue…
  2. It’s just the simplest name I could think of + this lib is mostly code that I wrote for my own projects and decided to open source it mostly as is.
  3. Seems like a good idea, but Routes is supposed to handle one thing and one thing alone which is easy routes access for frontend frameworks that use Phoenix as a backend.
Muco

Muco

Thank you for this package @RxAssim. Do you know if there’s any package that generates props types?

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews