Git Product home page Git Product logo

haskell-scotty-realworld-example-app's Introduction

RealWorld Example App

Haskell/Scotty codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

Build Status

This codebase was created to demonstrate a fully fledged fullstack application built with Haskell/Scotty including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to the Haskell/Scotty community styleguides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

Environment Variables

Name Desc Default Value
DATABASE_URL PostgreSQL Database URL postgresql://localhost/realworld
ENABLE_HTTPS Server will run on HTTPS if True True
PORT Port 3000
JWK_PATH Path to JWK signature file secrets/jwk.sig
JWT_EXPIRATION_SECS How long until JWT expire (in secs) 7200

Notable Dependencies

  • classy-prelude - Better Prelude for Haskell
  • scotty - Web framework library
  • postgresql-simple - PostgreSQL library
  • aeson - JSON serialization & deserialization
  • digestive-functors & digestive-functors-aeson - Input parsing & validation
  • jose-jwt - JWT encode & decode
  • slug - Slug string builder
  • hspec - Test framework

Quick Repo Walkthrough

  • /postgresql - Database migration scripts.
  • /secrets - Default HTTPS & JWT configuration files for development. Please replace with something else for production.
  • /scripts - Bash scripts to help development.
  • /app - Haskell files for application entry point.
  • /test - Haskell test files.
  • /src - Main Haskell code.

Getting started

Installation

Install Stack.

Install PostgreSQL.

Clone the repository and cd to repo

git clone https://github.com/eckyputrady/haskell-scotty-realworld-example-app.git

cd haskell-scotty-realworld-example-app

Install GHC

stack setup

Install dependencies and build project

stack build

Run project

stack exec realworld-exe

Alternatively, to watch file changes and start the server automatically

./scripts/dev.sh

Alternatively, to watch file changes and run the tests automatically

stack test --file-watch --coverage

To setup deployment to Heroku, please configure this custom buildpack

heroku buildpacks:set https://github.com/mfine/heroku-buildpack-stack

Misc

Logo image - credits to @EricSimmon

haskell-scotty-realworld-example-app's People

Contributors

eckyputrady avatar ibrahimsag avatar vjousse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

haskell-scotty-realworld-example-app's Issues

Failed to compile

I've got following compiling error

/Users/hao/Sandbox/form-as-api/src/Feature/Auth/JWT.hs:19:5: error:
    • Could not deduce (Control.Monad.Fail.MonadFail
                          (Either TokenError))
        arising from a do statement
        with the failable pattern ‘Jws (_, claimsRaw)’
      from the context: JWT r m
        bound by the type signature for:
                   resolveToken :: forall r (m :: * -> *).
                                   JWT r m =>
                                   Token -> m (Either TokenError CurrentUser)
        at src/Feature/Auth/JWT.hs:13:1-71
    • In a stmt of a 'do' block:
        Jws (_, claimsRaw) <- first (TokenErrorMalformed . show) eitherJwt
      In the second argument of ‘($)’, namely
        ‘do Jws (_, claimsRaw) <- first
                                    (TokenErrorMalformed . show) eitherJwt
            jwtClaims <- first TokenErrorMalformed
                           $ Aeson.eitherDecode $ fromStrict claimsRaw
            let (IntDate expiredAt)
                  = fromMaybe (IntDate curTime) $ jwtExp jwtClaims
            when (expiredAt < curTime) $ Left TokenErrorExpired
            ....’
      In a stmt of a 'do' block:
        userId <- either throwError return
                    $ do Jws (_, claimsRaw) <- first
                                                 (TokenErrorMalformed . show) eitherJwt
                         jwtClaims <- first TokenErrorMalformed
                                        $ Aeson.eitherDecode $ fromStrict claimsRaw
                         let (IntDate expiredAt)
                               = fromMaybe (IntDate curTime) $ jwtExp jwtClaims
                         when (expiredAt < curTime) $ Left TokenErrorExpired
                         ....
   |
19 |     Jws (_, claimsRaw) <- first (TokenErrorMalformed . show) eitherJwt
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

here's my stack.yml

# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-14.7

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
#    git: https://github.com/commercialhaskell/stack.git
#    commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#  subdirs:
#  - auto-update
#  - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# using the same syntax as the packages field.
# (e.g., acme-missiles-0.3)
extra-deps:
  - digestive-functors-0.8.4.0
  - digestive-functors-aeson-1.1.27
  - string-random-0.1.0.0

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.9"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor

Test failure

I tried to run the test suite with stack test, and I've got an error saying

✔ ~/Sandbox/haskell-scotty-realworld-example-app [master|✔]
22:54 $ stack test
realworld-1.0.0.0: test (suite: realworld-test)

realworld-test: libpq: failed (FATAL:  database "hao" does not exist
)

realworld-1.0.0.0: Test suite realworld-test failed
Test suite failure for package realworld-1.0.0.0
    realworld-test:  exited with: ExitFailure 1
Logs printed to console

would you please what else I have to do to have the test up & running? cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.