Chapter 4 Building a REST API

4.1 REST API 101

4.1.1 About express

4.1.2 Example

const express = require('express');
const {library} = require('hordes');
const app = express();
const stats = library("stats");

app.get('/iris', async (req, res) => {
    try {
        const output = await jsonlite.toJSON("iris")
        res.send( output )
    } catch(e){
        res.status(500).send(e)
    }
})

app.get('/mtcars', async (req, res) => {
    try {
        const output = await jsonlite.toJSON("mtcars")
        res.send( output )
    } catch(e) {
        res.status(500).send(e)
    }
})

app.listen(2811, function () {
  console.log('Example app listening on port 2811!')
})

4.2 REST API Design pattern with hordes

4.2.1 R package

// TODO

4.2.2 Infrastructure

// TODO

4.2.3 Example

// TODO