

Fortune.js - RESTful, HATEOAS APIs made easy - daliwali
http://fortunejs.com

======
tehwebguy
This is really cool - it reminds me of Sails.js [0] but is simply a node
module you can include in package.json without having to use custom commands
to launch the app.

Something they should put as a huge feature at the top (IMO) is that it uses
Express & supports Connect middleware.

[0] [http://sailsjs.org](http://sailsjs.org)

~~~
daliwali
Actually, one of my motivations to build this stems from Sails.js. Its ORM,
Waterline, currently doesn't support associations between resources, so I
built a persistence layer that does that myself. This is crucial because in
order to fully support the concept of HATEOAS, resources need to be able to
link to each other.

In the future, I might actually cut out Express from this framework, but still
accept Connect middleware. The reason for that is because I don't want the
user to be concerned about routing or having to manually set routes, so a
thinner router might be in order.

~~~
tehwebguy
OK, it looks like hooking this up with Angular directly is not going to work
without pretty major changes. Angular's resource module is set up to work with
"broken" JSON APIs out of the box, presumably because most are set up that
way.

Angular has way more to it so I'm probably going to leave it as is and
continue hacking away at Fortune to make it a little more forgiving with the
requests it handles.

I also exposed one more express method in /fortune.js:

    
    
        Fortune.prototype.static = function() {
          return express.static.apply(express, arguments);
        };
    

Since Angular is all client side just creating a public folder was enough to
serve up the required pages from the same app:

    
    
        app.use(app.static(__dirname + '/public'));

~~~
daliwali
Ah, by the way, you shouldn't need to serve the front-end app from the same
server as the API. By default, Fortune gives you CORS (Cross Origin Resource
Sharing), so that clients from any domain can consume it.

Also, Fortune should work out the box with Ember Data and my JSON API adapter:
[https://github.com/daliwali/ember-json-
api](https://github.com/daliwali/ember-json-api) . Not to say that you should
ditch Angular, but it will probably need quite a bit of modifications to its
data layer to get it working with the JSON API spec.

I will be working on a full, non-trivial example of what an Ember.js +
Fortune.js application can be in the coming week(s). There is a current
implementation that's in production at my company, but its unfortunately
closed-source.

------
joeblau
I can't believe I missed this post! This project is amazing.

