This page covers Tutorial v2. Elm 0.18.

Backend

We will need a backend for our application, we can use json-server for this.

json-server is an npm package that provides a quick way to create fake APIs.

Start a new node project:

yarn init

Accept all the defaults.

Install json-server:

yarn add [email protected]

Make api.js in the root of the project:

var jsonServer = require('json-server')

// Returns an Express server
var server = jsonServer.create()

// Set default middlewares (logger, static, cors and no-cache)
server.use(jsonServer.defaults())

var router = jsonServer.router('db.json')
server.use(router)

console.log('Listening at 4000')
server.listen(4000)

Add db.json at the root:

{
  "players": [
    { "id": "1", "name": "Sally", "level": 2 },
    { "id": "2", "name": "Lance", "level": 1 },
    { "id": "3", "name": "Aki", "level": 3 },
    { "id": "4", "name": "Maria", "level": 4 },
    { "id": "5", "name": "Julian", "level": 1 },
    { "id": "6", "name": "Jaime", "level": 1 }
  ]
}

Start the server by running:

node api.js

Test this fake API by browsing to:

results matching ""

    No results matching ""