angularjshttp-getangular-httphttp-parameters

$http.get('url', { params: { email: email } }); sending request with empty params


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
        });
    }
});

Solution

  • 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) ...