Data persistence module for flatiron based on JSON Schema

npm install restposten
16 downloads in the last month


Restposten is a data persistence module for flatiron. It's an adaptation of resourceful. You can replace resourceful in your flatiron app by Restposten. It uses JSON Schema draft v4 for data validation. It also has support for JSON Schema links, which are directly mapped to relations in the internal data model. Being a replacement for resourceful you can use it with restful, too.


npm install restposten

You also have to provide a database engine, a cache and a JSON Schema validator.

Currently, there are two database engines: restposten-mongodb.

npm install restposten-mongodb

The recommended schema validator is JaySchema.

npm install jayschema

API documentation

You can find the API docs at


Simple example

This example uses restposten-mongodb and JaySchema.

var restposten = require('restposten');
var mongo = require('restposten-mongodb');
var JaySchema = require('jayschema');

restposten.validator = new JaySchema();

mongo.connect({ host: 'localhost', port: 27017 }, function (err, db) {
  if (err)
    throw err;

  restposten.database = db;

  // Example schema
  var userSchema = {
    "$schema": "",
    "id": "",
    "title": "user",
    "description": "System user",
    "required": [ "id", "email" ],
    "properties": {
      "_id": {
        "type": "string"
      "name": {
        "type": "string"
      "email": {
        "type": "string",
        "format": "email"

  // Register a schema for validation.
  // This is only required, if you have schemas that reference each other.

  // Define the User resource.
  var User = restposten.define('user', userSchema);

  // Create a user, who's missing an email address. This will throw an error.
    "_id": "pvorb",
    "name": "Paul Vorbach"
  }, function (err, u1) {
    if (err)
      throw err;


See the JSON Schema specification for more advanced examples and further documentation on JSON Schema.

More advanced examples

You can see more advanced examples in examples/.

Generating the documentation

You need to have JSDoc 3 installed to be able to generate the API documentation files. Once you have JSDoc 3 installed, check out the Repository once again with the name "restposten-pages" into the same directory that contains "restposten". Then you have to checkout the branch gh-pages (git checkout gh-pages). Afterwards, you should be able to run

$ sh

When the script finishes, the documentation in "restposten-pages" should be up-to-date.



MIT License

npm loves you