Function for setting HTTP Status interfaces and an object for content
quickly.
Note: Metadata is wrapped in
meta
obj.
npm i status-interfaces
si(code, [{content}], [[error objects]])
import si from 'status-interfaces'
router.get(`/:id`, ctx => {
const record = find(dataSource, o => o.id === Number(ctx.params.id))
if (record) {
ctx.body = si(200, {
record
})
} else {
ctx.body = si(404, undefined, [ // this doesn't actually work because Koa doesn't escape here. I'll write some Koa middleware when time allows.
{
code: 1,
text: `Ya dun goofed...`
}
])
}
})