Added  encoding negotiation to node API and refactor handle_response into multiple functions
api.lua: Improved code formatting