npm install headrest
Assumes you init your JS app with or otherwise set an api root URL from which your models build the correct URL for their resource.
You can set the apiRoot like:
headrest = require'headrest'apiRoot: '/apis/'dbPath: '/tmp/gruntest.json'# headrest is an express appheadrestlisten5001
It assumes your resources have paths like:
/api/rocksor nested as deep as you like -
/api/rocks/ffeedc/sedimentariesand so on.
/api/rocks/ffeedc, also nested as far as you want.
Implements sessions at
POST whatever you want to
/api/session, you'll get a Cookie.
/api/session - HTTP 200 means you're logged in, 404 if not.
/api/session - removes your session record and sets your cookie
headrest = require'headrest'apiRoot: '/apis/'dbPath: '/tmp/gruntest.json'=gruntloadNpmTasks'grunt-contrib-connect'gruntregisterTask'headrest''connect'gruntinitConfigconnect:headrest:options:port: 5001hostname: "0.0.0.0"keepalive: true:headrest
This will start the server on
http://0.0.0.0:5001/. From a browser, you
can create an object with:
var request = $request// console output:// > 7cf28fd544be1b7f55296c45d40538fvar request = $requestvar request = $request
Or if any of this code is wack and you think there's a better way to do it, I definitely want to hear about it, no joke.
I yanked this idea from my homie Mark's footrest.py