Prototype JSON APIs with Fortune.js
If you hadn’t heard, JSON API is a format for building awesome APIs on top of JSON. You can see other posts tagged with JSON API here.
Recently, a new project related to JSON API was released: Fortune.js.
Fortune.js, a web framework for prototyping rich hypermedia APIs, allows you to rapidly prototype the server side of any JSON API api.
Check it out:
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 will give you all the proper routes and format the responses in the right way to conform with the spec.
If you didn’t guess, fortune.js makes heavy use of Node, so you can get it from npm
:
$ npm install fortune
I am super pumped about projects like this, because it shows off the great benefits of standardizing around a type like JSON API. Tooling that knows how to handle the type makes it really easy to get off the ground.
Discussion
Sign in or Join to comment or subscribe