added support for post/put/delete requests
removed code duplication