Skip to content

Exemplary real world application built with PureScript + Payload + PostgreSQL

License

Notifications You must be signed in to change notification settings

jim108dev/purescript-payload-realworld-example

Repository files navigation

PureScript Payload RealWorld Example

This is a learning project in order to set up a REST API with PureScript Payload and PostgreSQL. The specification follows

Install

  1. Install PureScript.

  2. Install repository 's software:

    1. Run:
    # This repo
    git clone https://github.com/jim108dev/purescript-payload-realworld-example.git
    
    cd purescript-payload-realworld-example
    
    npm install pg decimal.js xhr2 jsonwebtoken
    spago install
    spago build

Development/Test Mode

Please choose if you want to run the server in development/test (Dev) mode or in production mode (Prod). Dev operates with fixed timestamps which is required for the automated tests to run. Prod operates with the current system time.

  1. Database Setup:

    1. Install PostgreSQL.
    2. sql/CreateDB.sql: Execute commands which set up a database called conduit.
    3. config/Server/{Dev|Prod}.json: Change config files according to your db setup.
    4. sql/Functions.sql: Execute commands which set up functions/triggers for Prod.
    5. sql/ResetTables.sql: Activate the current timestamps by uncommenting -- TIMESTAMP for Prod. This file can be executed with:
    spago run -m Test.ResetTables
  2. Jwt: config/Server/Prod.json: Change the token's secret key for Prod.

  3. Server: src/Server/Main.purs: Set the configuration file accordingly.

  4. Optional: Install HTTPie and httpie-jwt-auth for testing via command line.

  5. Optional: Install a frontend like Real World Halogen.

Usage

  1. Run the server:

    spago run 
  2. API-SPEC.md lists HTTPie test calls to every request.

  3. Run a frontend.

Development

  1. Run the unit tests

    spago run -m Test.Main

APPROACH.md contains some comments about the decisions which were made.