Helix

Helix - Haskell web framework

Download as .zip Download as .tar.gz View on GitHub

Helix Hackage Hackage-Deps Build Status Join the chat at https://gitter.im/ajnsit/helix

Helix is a micro web framework for Haskell. It was extracted from Wai Routes and aims to provide functionality beyond simple typesafe URLs.

Helix is based on the Haskell Web Application Interface and uses it for most of the heavy lifting. It also provides a convenient but thin veneer over most of the wai API so it is unnecessary to directly use raw wai APIs when building web apps.

Much of Helix's typesafe URL functionality was pulled from the corresponding features in Yesod. Helix however, adds new routing features as well such as the ability to use subsites within route hierarchies.

Features

Helix adds the following features on top of wai -

Performance

When it comes to performance, Helix compares quite favorably with other Haskell web development micro frameworks.

See more details here - philopon/apiary-benchmark

result

Example Usage

Helix comes with several examples in the examples/ directory. New examples are being added regularly.

Example 1. Hello World - Code

A simple hello-world web app with two interlinked pages. This provides the simplest example of using routing and linking between pages with typesafe routes.

Example 2. Hello World with Subsites - Code

Similar functionality as the first example, but uses a hello world subsites to provide the hello world functionality. A subsite is an independently developed site that can be embedded into a parent site as long as the parent site satisfies a particular api contract. It's easy to swap out subsites for different functionality as long as the api contract remains constant.

Example 3. Using Blaze-HTML to generate HTML - Code

A simple example of how to generate HTML using blaze-html combinators in your handlers.

Example 4. Using Shakespearean Templates (hamlet, cassius, lucius, julius) to generate HTML/CSS/JS - Code

A simple example of how to generate HTML/CSS/JS using shakespearean templates. You can use both external and inline templates.

Example 5. Building a JSON REST Service - Code

Provides a simple example of how to build JSON REST services with helix. Uses Aeson for JSON conversion. Note that this example just demonstrates the web facing side of the application. It doesn't permanently persist data, and is also not threadsafe. You must use a more robust data storage mechanism in production! An example of doing this with a Relational DB adapter (like persistent) is in the works.

Example 6. Stream a response - Code

Wai has had the ability to stream content for a long time. Now helix exposes this functionality with the stream function. This example shows how to stream content in a handler. Note that most browsers using default settings will not show content as it is being streamed. You can use "curl" to observe the effect of streaming. E.g. - curl localhost:8080 will dump the data as it is being streamed from the server.

Example 7. Kitchen sink - Code

Work in progress. Demonstrates all major features in helix.

Example 8. Unrouted - Code

Demonstrates "unrouted" applications. These require no TH, or GHC extensions. Basically allow you to sequence request handlers in a cascade, with each handler having the full functionality of HandlerM monad available to them. Each handler also has access to untyped (but parsed) route information. Unrouted handlers are freely mixable with typesafe routing.

Deployment

The current recommended route (pun not intended) for deploying helix apps is keter. You need to read the port from the environment variables -

-- Run the application
main :: IO ()
main = do
  port' <- getEnv "PORT"
  let port = read port'
  run port $ waiApp application

Then put something like this in config/keter.yaml -

exec: ../path/to/executable
host: mydomainname.example.com

Then create a tarball with config/keter.yaml, path/to/executable, and any other files needed at runtime for your application. Rename the tarball to have a .keter extension.

Upload that file to your server's incoming folder for keter to pick it up. You obviously need keter already installed and configured properly at the server.

Planned Features

The following features are planned for later releases -

Changelog