Data serialization middleware for Node.js and web browsers.
Fortune provides data serialization middleware, from storage up to the presentation. It covers the whole application system including the data access layer (adapter), business logic layer (transform), and presentation layer (serializer). These layers working together allow for multiple data sources to be exposed via multiple formats through a uniform interface.
View the website for documentation. Get it from
$ npm install fortune --save
There is roughly 2.7k lines of code each for Node.js and the web browser (3.2k shared), and its size is about 22kb (min+gz).
Let's build an API that models Twitter's basic functionality:
// store.jsconst fortune = require'fortune'moduleexports = fortunedefineType'user'name: type: String// Following and followers are inversely related (many-to-many).following: link: 'user' inverse: 'followers' isArray: truefollowers: link: 'user' inverse: 'following' isArray: true// Many-to-one relationship of user posts to post author.posts: link: 'post' inverse: 'author' isArray: truedefineType'post'message: type: String// One-to-many relationship of post author to user posts.author: link: 'user' inverse: 'posts'
// server.jsconst http = require'http'const fortune = require'fortune'const store = require'./store'// The `fortune.net.http` helper function returns a listener function which// does content negotiation, and maps the internal response to a HTTP response.const server = httpcreateServerfortunenethttpstorestoreconnectthen => serverlisten1337
See the plugins page for more details.
This software is licensed under the MIT license.