JS from Routes

Public
Generates path helpers and API requests automatically from your Rails routes
Icons/chart bar
Used 177 times
Created by
M Maximo Mussini

Usage
JS from Routes generates path helpers and API methods from your Rails routes, allowing you to be more productive and prevent routing-related errors.

Since code generation is fully customizable it can be used in very diverse scenarios.

Features
⚡️

🚀 Productive
No need to specify the URL, just use the controller and action name, preventing mistakes and saving development time.

Path helpers are generated automatically whenever Rails reload is triggered.

🎩 Elegant

Make network requests with simple function calls, which return promises.

JSON serialization/deserialization works out of the box, but you can easily opt-out by choosing a different response type.

Safe

If an action is renamed or removed, it can be detected by static analysis or the TypeScript compiler.

Path helpers are fully typed, and client libraries are entirely written in TypeScript.

🛠 Customizable

Select a network library such as native fetch, axios, or use your own code.

Choose different conventions by customizing how code is generated.

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/X6ksgn"
Template Source

Review the code before running this template on your machine.

run "spring stop"

gem_group :development do
  gem "js_from_routes"
end

Bundler.with_unbundled_env { run "bundle install" }
run "CI=true npx --package @antfu/ni -- ni @js-from-routes/client"

run "echo 'Visit https://github.com/ElMassimo/js_from_routes for more info'"
Comments

Sign up or Login to leave a comment.