Skip to content

andrewMacmurray/realworld-backend-elm

Repository files navigation

RealWorld Backend in Elm

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

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

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

What?

We have a few frontend Elm implementations of the RealWorld App Spec, let's make a backend one!

See a full stack Elm version here! (It's rtfeldman/elm-spa-example connected up to this api as the backend).

How it works

The Elm API

  • The api is an Elm worker running on NodeJS, and uses elm-concurrent-task to interop with a few JS libraries and a Postgres database.
  • All of the business logic can be found in Routes.elm and in Domain modules.
  • Each endpoint handler is a ConcurrentTask which handles a thin layer of interop with some JS libraries (bcryptjs, jsonwebtoken and node-pg).
  • All of the code in Lib is pretty generic and could more or less be extracted out into separate packages as is (For JWT, Bcrypt, Postgres and an Http Server).

Deployment

Run Locally

Make sure you have NodeJS and Postgres installed.

Install dependencies with:

npm install

Database Setup

Create a postgres database with:

CREATE DATABASE realworld_api

Run the schema migration with:

psql -d realworld_api -a -f ./db/migrations/v1_initial_schema.up.sql

Running the api

Add the following environment variables:

export POSTGRES_URL=postgresql://localhost/realworld_api
export JWT_SECRET=sUpErSecReTjWtSecreT123456
export PORT=3000

Run the api in dev mode with:

npm start

This starts the api with a single express endpoint.

Import the Postman Collection to try out interacting with the api.

About

Realworld API backend implementation in elm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published