0

I am trying to pass variables from my angular frontend to my python/tornado backend. Here is my code.

// JS
var columns = ["col_A", "col_B", "col_C"];
var url = "working url, I confirmed it hits the server before I tried passing parameters";
var req = {
    method: "GET",
    headers: {
        'Content-Type': undefined
    },
    data: {
        "columns": columns
    }
}
return $http.get(url, req);

/*
    I also tried

    var req = {
        url: url,
        method: "GET",
        headers: {
            'Content-Type': undefined
        },
        data: {
            "columns": columns
        }
    }
    $http.get(req);

    but got a 404 with this
*/

---------------------------------------------------------------------------------------------

## python
import tornado.web
import tornado.gen as gen

class MyRequestHandler(tornado.web.RequestHandler):

    def __init__(self, *args, **kwargs):
        super(MyRequestHandler, self).__init__(*args, **kwargs)

    @gen.coroutine
    def get(self, *args, **kwargs):
        import pdb
        pdb.set_trace()
        # ... rest of the get function


 ## later on
 http = tornado.web.Application([
     (r"/working route", MyRequestHandler, {}),
     ... etc

So after my code pauses with the pdb.set_trace() statement to debug, I take a look at the variables. Looking at self.request, I see a bunch of possibly relevant stuff to my request (protocol, host, headers, etc) but I can't figure out how to get access to the parameter "columns". I tried

print self.get_argument("columns")

and got a 404. I'm really stumped. What am I doing wrong with this setup? I'm thinking this must be possible and I've just missed something really stupid.

Zack
  • 13,454
  • 24
  • 75
  • 113
  • 1
    See http://stackoverflow.com/questions/13760070/angularjs-passing-data-to-http-get-request for more details on passing data in a GET request – Joe Pontani Aug 06 '15 at 15:30

1 Answers1

2

Use Params instead of date in your $http call which will cause the data to be parameterized for GET calls

You can use 'data' if you are doing really anything else

var req = {
    method: "GET",
    headers: {
        'Content-Type': undefined
    },
    params: {
        "columns": columns
    }
}

Angular $http

Teliren
  • 342
  • 1
  • 5