Serve API through rest-sugar

Now the API is more versatile. Also cleaned up the codebase a bit while
at it.