API tweaks

Initial work on API and looking at indexes for query patterns.
I was getting no stacktrace on debug, just errors on the middle ware stack i inserted, with no printout. It could have been a funky env setup but i ended up giving up. 

If we can get it working properly and passing the raised error back up the stack to the rack error handler middlewares then i'm all for it.