Fork Me!

Hello nerds.

Fortune is a framework for prototyping hypermedia APIs that implement the JSON API specification. It comes with a modular persistence layer, with adapters for NeDB (built-in), MongoDB, MySQL, Postgres, & SQLite. See guide for how to use.


Current version is 0.2.4. Get it by installing from npm:

npm install fortune Download .zip

Basic Usage

Here is a minimal application that exposes two resources that can link to each other:

var fortune = require('fortune')
  , app = fortune({
    db: 'petstore'
  })
  .resource('person', {
    name: String,
    age: Number,
    pets: ['pet'] // "has many" relationship to pets
  })
  .resource('pet', {
    name: String,
    age: Number,
    owner: 'person' // "belongs to" relationship to a person
  })
  .listen(1337);

This exposes a few routes for the person and pet resources:

HTTP Person Pet Notes
GET /people /pets Get a collection of resources, accepts query ?ids=1,2,3...
POST /people /pets Create a resource
GET /people/:id /pets/:id Get a specific resource, or multiple: 1,2,3
PUT /people/:id /pets/:id Create or update a resource
PATCH /people/:id /pets/:id Patch a resource (see RFC 6902)
DELETE /people/:id /pets/:id Delete a resource
GET /people/:id/pets /pets/:id/owner Get a related resource (one level deep)

Please consult the JSON API specification for what the request and response should look like. Read the guide for an overview, or the documentation if you feel like diving in.


Batteries included, Fortune handles routing and database interactions so you don't have to.

Serializers and deserializers for JSON API, and other hypermedia formats (in the future).

Hooks to implement application specific logic before/after interacting with resources.