 H2O.Proxy = (_) ->
-  createResponse = (status, data, xhr) ->
-    status: status, data: data, xhr: xhr
+  doGet = (path, go) ->
+    $.getJSON(path)
+      .done (data, status, xhr) ->
+        go null, data
+      .fail (xhr, status, error) ->
+        message = xhr.responseJSON.errmsg or 'Unknown error'
+        go new Flow.Error message, new Flow.Error "Error calling GET #{path}"
 
-  handleResponse = (go, jqxhr) ->
-    jqxhr
+  doPost = (path, opts, go) ->
+    $.post(path, opts)
       .done (data, status, xhr) ->
-        go null, createResponse status, data, xhr
+        go null, data
       .fail (xhr, status, error) ->
-        go createResponse status, xhr.responseJSON, xhr
-
-  h2oGet = (path, go) ->
-    handleResponse go, $.getJSON path
-
-  h2oPost = (path, opts, go) ->
-    handleResponse go, $.post path, opts
-
-  processResponse = (go) ->
-    (error, result) ->
-      if error
-        #TODO error logging / retries, etc.
-        go error, result
-      else
-        if result.data.response?.status is 'error'
-          go result.data.error, result.data
-        else
-          go error, result.data
-
-  request = (path, go) ->
-    h2oGet path, processResponse go
-
-  post = (path, opts, go) ->
-    h2oPost path, opts, processResponse go
-
+        message = xhr.responseJSON.errmsg or 'Unknown error'
+        go new Flow.Error message, new Flow.Error "Error calling POST #{path} with opts #{JSON.stringify opts}"
   mapWithKey = (obj, f) ->
     result = []
     for key, value of obj

      path

  requestWithOpts = (path, opts, go) ->
    request (composePath path, opts), go

  encodeArray = (array) -> "[#{join (map array, encodeURIComponent), ','}]"


        go error, result.models

  requestModel = (key, go) ->
    doGet "/3/Models.json/#{encodeURIComponent key}", (error, result) ->
      if error
        go error, result
      else
        go error, head result.models

  requestModelBuilders = (algo, go) ->
    doGet "/2/ModelBuilders.json/#{algo}", go

  requestModelInputValidation = (algo, parameters, go) ->
    doPost "/2/ModelBuilders.json/#{algo}/parameters", parameters, go

  requestModelBuild = (algo, parameters, go) ->
    doPost "/2/ModelBuilders.json/#{algo}", parameters, go

  requestModelMetrics = (modelKey, frameKey, go) ->
    doPost "/3/ModelMetrics.json/models/#{encodeURIComponent modelKey}/frames/#{encodeURIComponent frameKey}", {}, go

  link _.requestInspect, requestInspect
  link _.requestFrames, requestFrames
