0

I am trying to send HTTP GET request with email in params in following code:

$http.get('api/me', {
    params: {
        email: email
    }
});

but at backend I am receiving empty params i.e. request.params is blank. I tried the other format of HTTP request i.e.

$http({
    url: 'api/me', 
    method: "GET",
    params: {email: email}
});

but result is same i.e. empty params at backend.

My backend code:

User.findOne({ email: request.params.email }, function(error, user) {
    if (error) {
        throw error;
    } else if (!user) {
        response.json({
            message: "User doesn't exist.",
            status: 0
        });
    } else {
        response.json({
            message: "Successfully logged in.",
            status: 1,
            data: user
        });
    }
});
Rusty
  • 1,086
  • 2
  • 13
  • 27
  • First of all check if the email variable has a value assigned to it. Backend you should be expecting an "email" parameter with a value not "request.params" as you state in your question. Can you show your backend code? – cnorthfield Jul 30 '16 at 22:26
  • @papakia Yes. You are right. I misunderstood the format. Is there a way I can get the email in a format that allows me to fetch it as `request.params` or `request.headers` or `request.body` (although I don't want `request.body` since it is a `GET` request). I have also edited the question and added my backend code. – Rusty Jul 30 '16 at 22:39
  • Are you using Express? If so then see the answer posted here: http://stackoverflow.com/a/9243020/3453034 – cnorthfield Jul 30 '16 at 22:46
  • @papakia Thanks, I guess this should solve my issue. – Rusty Jul 30 '16 at 22:50

1 Answers1

1

You should not use the params to send data. Instead, use data itself

$http({
    url: 'api/me', 
    method: "GET",
    data: {email: email}
});

and then in the back end:

User.findOne({ email: request.email }, function(error, user) ...
bzim
  • 1,002
  • 9
  • 17