From 93fe36c33205a8c8bd9ded2e4dd0ebe524ecebbb Mon Sep 17 00:00:00 2001 From: Greg Hale Date: Wed, 21 Sep 2016 10:54:26 -0400 Subject: [PATCH] Readme and build script cleanup --- README.md | 97 +++++++++++++++++++------------------------------- build.sh | 4 +-- exec/toSite.sh | 2 ++ 3 files changed, 41 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 56cf962..129f174 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,13 @@ # servant-reflex -[![Build Status](https://travis-ci.org/imalsogreg/servant-reflex.svg?branch=dynamic)](https://travis-ci.org/imalsogreg/servant-reflex) +[![Build Status](https://travis-ci.org/imalsogreg/servant-reflex.svg?branch=master)](https://travis-ci.org/imalsogreg/servant-reflex) + +## The problem `servant-reflex` solves + +Keeping your frontend in sync with your API server can be difficult - when the API changes its input parameters or return type, XHR requests from the frontend will fail at runtime. If your API is defined by [servant](haskell-servant.readthedocs.io) combinators, you can use `servant-reflex` to share the API between the server and frontend. +Syncronization between is checked at compile time, and rather than building XHR requests by hand, API endpoints are available behind `reflex`'s FRP semantics. -This library lets you automatically derive [`reflex-dom`](https://github.com/reflex-frp/reflex-dom) clients that query each endpoint of a [`servant`](htps://github.com/haskell-servant/servant) webservice. - -## Building the library and test server - -### With `reflex-platform`: - -First build the library: - -``` -git clone https://github.com/imalsogreg/servant-reflex -cd servant-reflex -git submodule update --init --recursive -./build.sh -./toSite.sh -``` - -(the `toSite.sh` script copies the generated javascript to the server's static assets directory) - - -Then build the test server (not in a nix-shell): - -``` -./init-sandbox.sh -cd testserver && cabal install --only-dep && cabal build && cd .. - -``` - - -### Or, with a system-wide ghcjs - -You will need a recent [GHCJS installation](https://github.com/ghcjs/ghcjs), or use the [reflex-platform](https://github.com/reflex-frp/reflex-platform). A [snap](https://github.com/snapframework) server using [servant-snap](https://github.com/haskell-servant/servant-snap) is provided for serving the api. `Snap 1.0` is not yet on Hackage (and servant-snap is still experimental), but we bundle the sources as a git submodule. To install everything with cabal: - -``` -git clone https://github.com/imalsogreg/servant-reflex -cd servant-reflex -git submodule update --init --recursive -./init-sandbox.sh -cd testserver && cabal install --only-dep && cabal build && cd .. -cabal install --only-dep -cabal build -./toSite -``` - -The `toSite.hs` script copies the ghcjs-generated files into the server's static directory. - -## Running the example site - -The server must be run from the directory where static assets live: - -``` -cd testserver -dist/build/back/back -p 8001 -``` - -And simply browse to `localhost:8001` ## Example @@ -156,8 +106,35 @@ This example builds some input fields to enter API parameters, buttons to trigge For a great introduction to recative DOM building, see the [README](https://github.com/reflex-frp/reflex-platform) for the `reflex-platform`. For more information about servant, see their [documentation](http://haskell-servant.readthedocs.io/en/stable/). Thanks to the respective authors of these fabulous libraries. -## TODOs - - Request Headers - - Tests - - Code cleanup +## Building the library and test server + +This repository comes with a small example of an API shared between a ghcjs-compiled frontend ([exec/](https://github.com/imalsogreg/servant-reflex/tree/master/exec)) and a ghc-compiled backend ([testserver/](https://github.com/imalsogreg/servant-reflex/tree/master/testserver). To build these components: + + +First build the library: + +``` +git submodule update --init --recursive +./build.sh +``` + +Then build the test server: + +``` +deps/reflex-platform/work-on ./overrides-ghc.nix ./testserver --command "cd testserver && cabal build" +``` + + +## Running the example site + +The server must be run from the directory where static assets live: + +``` +cd testserver +dist/build/back/back -p 8001 +``` + +And simply browse to `localhost:8001` + +**For a larger example of a project that shares types between backend and frontend, see [hsnippet](https://github.com/mightybyte/hsnippet).** diff --git a/build.sh b/build.sh index 069fb28..eacc304 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,3 @@ -#!/bin/sh +#!/usr/bin/env bash -deps/reflex-platform/work-on ./overrides.nix ./. --run "cabal configure --ghcjs && cabal build && testdriver/toSite.sh" +deps/reflex-platform/work-on ./overrides.nix ./. --run "cabal configure --ghcjs && cabal build && exec/toSite.sh" diff --git a/exec/toSite.sh b/exec/toSite.sh index 1aca473..9924d2b 100755 --- a/exec/toSite.sh +++ b/exec/toSite.sh @@ -1 +1,3 @@ +#!/usr/bin/env bash + cp dist/build/example/example.jsexe/* testserver/static