- Api routes are copied by folder structure. At the root of each directory you must put a routes.js and/or a schemas.js (if you want schema validation) Sample api directory structure could look like this:
api
├── routes.js
├── schemas.js
└── user
├── :userId
│ └── routes.js
└── routes.js
-
Routes.js should be defined as an object with functions for each method (GET, POST etc), and you can return the result, as all method definitions are wrapped in Promises. I squash params into a single object, so query params, url params and body params are all in one object, and overwritten respectively.
-
Schemas.js should define schemas (if you want to use it). for each method. An "in" object and "out" object define the schemas for that coming in and out. I use ajv to validate - so you can find more there.
-
To run: We require express.
var express = require('express')
var app = express()
var sunio = require('<path/to/index/of/sunio>')
sunio.start(__dirname, app)
and you should be good to go!