Renamed 'docs' to 'result' and 'err' to 'error'

Added search by id
Moved api code to its own file