An I/O library for web applications.
Fortune is an I/O library for web applications.
View the website for documentation. Get it from
$ npm install fortune@latest --save
Currently beta software. Things will break, check the changelog.
Here is a minimal example application, including a web server:
import fortune from 'fortune'import http from 'http'const store = fortunecreateconst server = httpcreateServerfortunenethttpstore
This sets up an instance of Fortune with default options, and an HTTP server instance. The
fortune.net.http module returns a listener function that does content negotiation to determine which serializers to use for I/O, and forwards Node's built-in
response objects to the serializers.
storedefineType'user'name: type: Stringgroups: link: 'group' inverse: 'members' isArray: truestoredefineType'group'name: type: Stringmembers: link: 'user' inverse: 'group' isArray: true
Defining record types. There is a many-to-many relationship between
group on the
members fields respectively.
storeconnectthen => serverlisten1337
Finally we need to call
connect before we do anything with the instance. Then we can let the server listen, which yields a HTTP API that conforms to the Micro API and JSON API specifications. By default, it is backed by an embedded document store, NeDB, which doesn't persist to disk by default.
For the Micro API serializer, we get a set of internal pre-defined routes. Note that by default, the routes are obfuscated to the client, to encourage the use of hypermedia.
|Get the entry point including links to collections.|
|Get a collection of records belonging to that type.|
|Create a record belonging to that type.|
|Update records belonging to that type.|
|Delete an entire collection of records by type.|
|Get records of a type by comma separated IDs.|
|Update records of a type by comma separated IDs.|
|Delete records of a type by comma separated IDs.|
|Get related records corresponding to a type and IDs.|
|Update related records corresponding to a type and IDs.|
|Delete related records corresponding to a type and IDs.|
The JSON API serializer emits routes specified here.
Fortune is licensed under the MIT license.