Started to refactor api to accept JSON requests.