Updated api to return a response object, better handling of response headers