hyperbole: Interactive HTML apps using type-safe serverside Haskell

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Interactive serverside web framework Inspired by HTMX, Elm, and Phoenix LiveView


[Skip to Readme]

Properties

Versions 0.1.1, 0.1.2, 0.2.0, 0.3.5, 0.3.6, 0.4.2
Change log CHANGELOG.md
Dependencies base (>=4.16 && <5), bytestring (>=0.11 && <0.13), casing (>0.1 && <0.2), containers (>=0.6 && <1), cookie (>=0.4 && <0.5), effectful (>=2.4 && <3), file-embed (>=0.0.10 && <0.1), http-api-data (>=0.6 && <0.7), http-types (>=0.12 && <0.13), network (>=3.1 && <4), string-conversions (>=0.4 && <0.5), string-interpolate (>=0.3 && <0.4), text (>=1.2 && <3), time (>=1.12 && <2), wai (>=3.2 && <4), wai-websockets (>=3.0 && <4), warp (>=3.3 && <4), web-view (>=0.6.2 && <=1.0), websockets (>=0.12 && <0.14) [details]
License BSD-3-Clause
Author Sean Hess
Maintainer seanhess@gmail.com
Category Web, Network
Home page https://github.com/seanhess/hyperbole
Bug tracker https://github.com/seanhess/hyperbole/issues
Source repo head: git clone https://github.com/seanhess/hyperbole
Uploaded by seanhess at 2025-01-03T20:11:18Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for hyperbole-0.4.2

[back to package description]

Hyperbole

Hackage

Create interactive HTML applications with type-safe serverside Haskell. Inspired by HTMX, Elm, and Phoenix LiveView

Learn more about Hyperbole on Hackage

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Main where

import Data.Text (Text)
import Web.Hyperbole

main :: IO ()
main = do
  run 3000 $ do
    liveApp (basicDocument "Example") (runPage page)


page :: (Hyperbole :> es) => Eff es (Page '[Message])
page = do
  pure $ col id $ do
    hyper Message1 $ messageView "Hello"
    hyper Message2 $ messageView "World!"


data Message = Message1 | Message2
  deriving (Show, Read, ViewId)


instance HyperView Message es where
  data Action Message = Louder Text
    deriving (Show, Read, ViewAction)

  update (Louder msg) = do
    let new = msg <> "!"
    pure $ messageView new


messageView :: Text -> View Message ()
messageView msg = do
  row id $ do
    button (Louder msg) id "Louder"
    el_ $ text msg

Getting Started with Cabal

Create a new application:

$ mkdir myapp
$ cd myapp
$ cabal init

Add hyperbole and text to your build-depends:

    build-depends:
        base
      , hyperbole
      , text

Paste the above example into Main.hs, and run

$ cabal run

Visit http://localhost:3000 to view the application

Examples

The example directory contains an app demonstrating various features. See it in action at https://docs.hyperbole.live

Hyperbole Examples

Learn More

View Documentation on Hackage

View on Github

Full Production Example

National Solar Observatory

The NSO uses Hyperbole for the Level 2 Data creation tool for the DKIST telescope. It is completely open source. This production application contains complex interfaces, workers, databases, and more.

Local Development

Dependencies with Nix

With nix installed, you can use nix develop to get a shell with all dependencies installed.

Manual dependency installation

Download and install NPM. On a mac, can be installed via homebrew:

brew install npm

Install client dependencies

cd client
npm install

Recommended: Use direnv to automatically load environment from .env

brew install direnv
direnv allow

Building

Build JavaScript client

cd client
npx webpack

Run examples

cd example
cabal run

Tests

cabal test

File watching

Run tests, then recompile everything on file change and restart examples

bin/dev

Contributors