Important: This is the documentation for a previous version of Feathers.
For the latest documentation please visit

A REST API server

Our database connector will now function as a full fledged REST API server. We need only add a HTTP server to it.

HTTP servers. Feathers is currently tied into the popular HTTP server framework Express. Future versions will support multiple frameworks, starting with koa.

Working example

Implementing a REST API server

This is our previous example with the database method calls removed, and with an Express server added.

// Example - Create REST API

const expressServerConfig = require('../common/expressServerConfig');
const expressMiddleware = require('../common/expressMiddleware');
const rest = require('feathers-rest');
const NeDB = require('nedb');
const path = require('path');
const service = require('feathers-nedb');

const app = expressServerConfig()

const server = app.listen(3030);
server.on('listening', () => console.log(`Feathers application started on port 3030`));

function services() {
  this.use('/users', service({ Model: userModel() }));

function userModel() {
  return new NeDB({
    filename: path.join('examples', 'step', 'data', 'users.db'),
    autoload: true

The Express server common/expressServerConfig.js is configured as follows.

const bodyParser = require('body-parser');
const compress = require('compression');
const cors = require('cors');
const path = require('path');
const feathers = require('feathers');

module.exports = () => {
  const app = feathers()
    .options('*', cors())
    .use('/', feathers.static(path.join(__dirname, 'public')))
    .use(bodyParser.urlencoded({ extended: true }));

  return app;

The Express middleware common/expressMiddleware/index.js handles logging, pages not found, and general errors.

'use strict';

const handler = require('feathers-errors/handler');
const notFound = require('./not-found-handler');
const logger = require('./logger');

module.exports = function() {
  const app = this;


Boilerplate. The server configuration and middleware are standard Express. They have little to do with Feathers other than to feed REST requests to it.

Running the server

We can now make REST API calls to the server.

In the previous example we created 3 user items and then printed the user file. We can now do the same thing, but using REST, with curl commands:

printf "\nPOST Jane Doe\n"
curl -H "Content-Type: application/json" -X POST -d '{"email":"","password":"X2y6","role":"admin"}' http://localhost:3030/users
printf "\nPOST John Doe\n"
curl -H "Content-Type: application/json" -X POST -d '{"email":"","password":"i6He","role":"user"}' http://localhost:3030/users
printf "\nPOST Judy Doe\n"
curl -H "Content-Type: application/json" -X POST -d '{"email":"","password":"7jHw","role":"user"}' http://localhost:3030/users
printf "\nGET all users\n"
curl -X GET http://localhost:3030/users

First, start the server by running node ./examples/step/01/rest/1.js on one terminal.

Then run the curl commands with ./examples/step/01/rest/ on another terminal.


That console displays:

feathers-guide$ ./examples/step/01/rest/
POST Jane Doe
POST John Doe
POST Judy Doe
GET all users

Feathers. REST API calls are automatically converted into Feathers database method calls like the users.create() and users.find() methods we used in the previous example. How's that for convenience?

Is anything wrong, unclear, missing?

Leave a comment.

results matching ""

    No results matching ""