All Projects → tiagoengel → phoenix-jsroutes

tiagoengel / phoenix-jsroutes

Licence: MIT license
Javascript routing for the phoenix framework

Programming Languages

elixir
2628 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to phoenix-jsroutes

Elixir Companies
A list of companies currently using Elixir in production.
Stars: ✭ 1,475 (+5800%)
Mutual labels:  phoenix-framework
Phoenix Toggl
Toggl tribute done with Elixir, Phoenix Framework, React and Redux.
Stars: ✭ 176 (+604%)
Mutual labels:  phoenix-framework
phoenix assets webpack
Asset Pipeline with Webpack on Phoenix
Stars: ✭ 52 (+108%)
Mutual labels:  phoenix-framework
Phoenix Diff
See the changes needed when upgrading an Elixir Phoenix application
Stars: ✭ 120 (+380%)
Mutual labels:  phoenix-framework
Short url
🔗 short url app elixir Phoenix
Stars: ✭ 162 (+548%)
Mutual labels:  phoenix-framework
Realtime
Listen to your to PostgreSQL database in realtime via websockets. Built with Elixir.
Stars: ✭ 4,278 (+17012%)
Mutual labels:  phoenix-framework
Recognizer
A authentication and user service
Stars: ✭ 106 (+324%)
Mutual labels:  phoenix-framework
rent-bot
My personal Facebook Messenger chat bot that helped find an apartment to rent.
Stars: ✭ 91 (+264%)
Mutual labels:  phoenix-framework
Tune
A streamlined Spotify client and browser with a focus on performance and integrations.
Stars: ✭ 166 (+564%)
Mutual labels:  phoenix-framework
admissions
Admissions is the gateway to Elixir School's private Slack
Stars: ✭ 18 (-28%)
Mutual labels:  phoenix-framework
Phoenix Docker Compose
Docker development environment for Elixir+Phoenix
Stars: ✭ 131 (+424%)
Mutual labels:  phoenix-framework
Docker Phoenix
A dockerized Phoenix development and runtime environment.
Stars: ✭ 152 (+508%)
Mutual labels:  phoenix-framework
Phoenix Trello
Trello tribute done in Elixir, Phoenix Framework, React and Redux.
Stars: ✭ 2,492 (+9868%)
Mutual labels:  phoenix-framework
Phoenix Liveview Counter Tutorial
🤯 beginners tutorial building a real time counter in Phoenix 1.5.5 + LiveView 0.14.7 ⚡️
Stars: ✭ 115 (+360%)
Mutual labels:  phoenix-framework
phxsockets.io
Phoenix sockets and channels GUI client
Stars: ✭ 16 (-36%)
Mutual labels:  phoenix-framework
Sentinel
DEPRECATED - Phoenix Authentication library that wraps Guardian for extra functionality
Stars: ✭ 109 (+336%)
Mutual labels:  phoenix-framework
Phoenix And Elm
Example application using Elixir, Phoenix and Elm
Stars: ✭ 188 (+652%)
Mutual labels:  phoenix-framework
zero-to-graphql-using-elixir
The purpose of this example is to provide details as to how one would go about using GraphQL with the Elixir Language.
Stars: ✭ 20 (-20%)
Mutual labels:  phoenix-framework
pokerex client
Elm client for PokerEx project
Stars: ✭ 39 (+56%)
Mutual labels:  phoenix-framework
phoenix-cms
Headless CMS fun with Phoenix LiveView and Airtable
Stars: ✭ 72 (+188%)
Mutual labels:  phoenix-framework

PhoenixJsroutes

Elixir CI

Brings phoenix router helpers to your javascript code.

This project is a mix compiler task that generates a javascript module containing helpers to access your server routes.

Installation

Add the latest version to your mix.exs file:

def deps do
  [{:phoenix_jsroutes, "~> 2.0.0"}]
end

Compatibility

Version Phoenix Version
>= 1.0 >= 1.3
<= 0.4 <= 1.2

Getting started

Add the jsroutes compiler to the list of compilers in your project.

def project do
    [app: :jsroutes_test,
    ...
    compilers: [:phoenix, :gettext] ++ Mix.compilers ++ [:jsroutes]
    ...]
end

This compiler should be placed after the elixir compiler, this is important because your router module should be already compiled when this compiler runs

After that, if you run mix compile the file assets/js/phoenix-jsroutes.js will be generated.

You can clean up the generated file by running mix clean.

The location and file name can be changed (see Configuration section bellow), keep in mind that if you change it, mix clean will not be able to remove the old file. It's recommended to always run mix clean before you update this config.

Using the javascript helpers

The code is generated using ES6 modules syntax and work with the default Phoenix config using webpack.

The functions are generated with different names from the ones in the server in order to follow javascript best practices. For example:

user_path(:index)                => userIndex()
user_path(:create)               => userCreate()
user_path(:update, 1)            => userUpdate(1)
user_friends_path(:update, 1, 2) => userFriendsUpdate(1, 2)

Usage

// app.js
import * as routes from './phoenix-jsroutes'
routes.userIndex(); // /users
routes.userCreate(); // /users
routes.userUpdate(1); // /users/1
routes.userFriendsUpdate(1, 2); // /users/1/friends/2

You can also import only the routes you need

// app.js
import { userIndex, userUpdate } from './phoenix-jsroutes';
userIndex();
userUpdate(1);

Live reload

If you want the javascript module to be generated automatically when your router changes, just add this compiler to the list of reloadable compilers.

# config/dev.exs

config :my_app, MyApp.Endpoint,
  http: [port: 4000],
  ...
  reloadable_compilers: [:gettext, :phoenix, :elixir, :jsroutes]

NOTE: if you are using version >= 1.5 of Phoenix you might need to reload the page once or twice for changes to take effect.

Configuration

Key Type Default Description
output_folder String assets/static/js Sets the folder used to generate files
include Regex nil Will include only routes matching this regex
exclude Regex nil Will include only routes not matching this regex

Configurations should be added to the key :jsroutes in your application.

config :my_app, :jsroutes,
  output_folder: "assets/static/js",
  include: ~r[/api],
  exclude: ~r[/admin]

Contributing

Contributions are very welcome. If you want to contribute to this project first open an issue so we can discuss your ideas, if you're confident in implementing it, fork the project and create a pull request. Thank's in advance :).

Contributors

Special thanks to the amazing people who have helped me start this project.


Marcio Junior
Horacio Fernandes
Diogo Kersting
Paulo

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].