Implement #447 : added stats json api by type and state

Here's the implementation of the stats route.
Let me know if you need more stuff.
EDIT: Wrong issue number. Will change commit message