Leverage the World Wide West with Farwest
Coming soon to a desert near you.
Loïc Hoguin - @lhoguin
Erlang Cowboy and Nine Nines Founder
How soon?
- Farwest is the result of months of research
- It still needs a few months of development
- Early feedback is more than welcome
Current solutions in Erlang
Nitrogen
- Web development for Erlang developers
- HTML built using Erlang records
- Built-in JS for many components and actions
ChicagoBoss
- Erlang development for Rails developers
- ErlyDTL templates
- No constraints on frontend libraries used
Zotonic
- The Erlang CMS
- Big plugin-based architecture, with ErlyDTL templates
- Many constraints on how the development should be done
Lightweight server solution
- Choose your own
adventure server
- No constraint on any frontend or backend libraries
- A lot more work to set everything up
Problems
Erlang developers suck at Frontend
- They know how to write code, not UI
- Writing HTML in Erlang doesn't make them better
- UIs created by Erlang developers generally suck
- The Erlang developer should never touch frontend code
Frontend developers and Erlang
- They don't know what Erlang is
- They just need templates and assets
- They need to be able to write or update the templates
- They should do so without any Erlang knowledge
They have different concerns
- These concerns shouldn't overlap
- They need a common language to exchange information
REST is the key
- Erlang developers know REST
- Frontend developers already use REST APIs
- Make REST the common language between both sides
Farwest
Farwest for Erlang developers
- Strictly work only on backend logic
- No HTML, CSS or JS; it's the Frontend guy's job!
- REST API developer
- Get data in and out, that's it
- Same old Cowboy REST development you're used to do
Farwest is for Frontend developers
- Because they make your app pretty and easy to use
- None of the following Farwest features require Erlang knowledge
Installation and setup
- Install Erlang
- Download and untar a blank project template
- Start the server with ./start.sh
- This gives you a link to the integrated development interface
Continuous development
- Automatic code recompilation and reload
- Including templates, CSS and JS
- Only a refresh of the page is needed to view the changes
Built for REST
- Development tools for REST, with a Web UI
- Javascript libraries to simplify REST manipulation
- Crawlers can still retrieve your content using GET
Backend API documentation
- Automatically generated
- Partially built using the resources exports
- Partially built from the edoc comments
- Available through the API explorer tool
Bullet enabled
- Always connected bidirectional stream with the server
- Receive server events as soon as they happen
- Events are mapped to JS callbacks
- Reply directly without opening a new connection
REST over Bullet
- Call the API over the Bullet stream
- Request is sent as JSON, converted to a Req object, then dispatched
- Request is asynchronous, similar to jQuery.ajax()
Routing
- Uses Cowboy's dispatch list mechanism
- Includes a tool for configuring the dispatch list
- Dispatch list is reloaded live
Quick application scaffolding
- Predefined API enabled by default
- /data/: direct data storage access
- /dispatch/: direct dispatch list access
- /env/: direct environment data access
- /farwest/: development tools Web UI
Map URIs to data
- Map a URI to a scaffolding resource handler
- Resource handler receives a list of data queries
- URI components and query string can be used in queries
- Templates receive the queried data
- Configurable using the dispatch and query Web UIs
Not just scaffolding
- You can choose to keep these features enabled
- After adding some authentication of course
- They let the end user extend your application
- Like a wiki, but with separate data and templates
Remember?
- None of this requires Erlang knowledge
- They can write their application without knowing Erlang
- They can write their application before the backend is ready
- They may not even need a custom backend API
Farwest is still Erlang
- Concurrent
- Fault-tolerant
- Easily distributed
- And one more thing...
Live frontend upgrades
- Available as part of release upgrades
- Upgrade the page's CSS, JS or media files live
- When not possible, a callback can be called instead
- This one obviously requires an Erlang developer
Technical overview
Modular Farwest
- Base Farwest contains the core, tools and scaffolding
- Plugins are rebar dependencies
- Write your application as a standard OTP application
- Or write many Farwest plugins for reusability
Farwest plugins
- Plugins are OTP applications
- At startup, plugins register themselves with Farwest
- They provide resources, OTP services, assets, tools
OTP compliant
- Generate OTP releases of your applications
- Upgrade Farwest or its plugins
- Connect several Farwest nodes
Made for the web
- Automatic minifying and merging of CSS/JS files
- User authentication (plugins)
- Internationalization and unicode support
Dependencies
- Cowboy, Bullet, Sheriff, Goldrush/Saloon
- ErlyDTL, JSX
- Gproc
- Bootstrap, jQuery
- Undecided storage backend
Undependencies
- You don't have to use most dependencies
- Farwest does not enforce how you build the application
License
- ISC License (BSD simplified)
- Same as Cowboy
Timeline
- March 29th, 2012: This talk
- April 2nd, 2012: First commits
- EUC, 2012: Alpha
- London, 2012: Beta
You can help
- Follow the project
- Try it out as soon as it becomes available
- Send patches
- Sponsor the project
Links
- https://github.com/extend/farwest
- http://ninenines.eu
- #erlounge on Freenode
Questions?