Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 1.25 KB

resource.md

File metadata and controls

47 lines (34 loc) · 1.25 KB

Resource

rest-io supports adding custom actions on resources.

Quick Start

To create a Custom Resource you extend the Resource class:

import { Resource } from 'rest-io';

export default class BananaResource extends Resource {
  ...
}

Now you can overwrite the standard calls:

export default class BananaResource extends Resource {
  getAll(req, res) {
    res.status(200).send('awesome!');
  }
}

API

These are the functions you can overwrite or use:

getAll(req, res, next)

This is the callback of the express route handler.

getById(req, res, next)

This is the callback of the express route handler.

create(req, res, next)

This is the callback of the express route handler.

update(req, res, next)

This is the callback of the express route handler.

del(req, res, next)

This is the callback of the express route handler.

errorHandler(error, res)

The error that is triggered and the express res object to handle the result.

setupRoutes()

Make use of this.router to setup new routes.