AngularJS passing data to $http.get request

04/11/2020 10:00:01

I have a function which does a http POST request. The code is specified below. This works fine.

   url: user.update_path, 
   method: "POST",
   data: {user_id:, draft: true}

I have another function for http GET and I want to send data to that request. But I don't have that option in get.

   url: user.details_path, 
   method: "GET",
   data: {user_id:}

The syntax for http.get is

get(url, config)

Verified Answer (941 Votes)

12/07/2012 14:34:11

An HTTP GET request can't contain data to be posted to the server. However, you can add a query string to the request.

angular.http provides an option for it called params.

    url: user.details_path, 
    method: "GET",
    params: {user_id:}

See:$http#get and$http#usage (shows the params param)


Answer #2 (518 Votes)

08/29/2013 23:07:23

You can pass params directly to $http.get() The following works fine

$http.get(user.details_path, {
    params: { user_id: }

Answer #3 (43 Votes)

12/28/2015 12:04:06

Starting from AngularJS v1.4.8, you can use get(url, config) as follows:

var data = {

var config = {
 params: data,
 headers : {'Accept' : 'application/json'}

$http.get(user.details_path, config).then(function(response) {
   // process response here..
 }, function(response) {
Hack Hex uses Stack Exchance API by the Stack Exchange Inc. to scrape questions/answers under Creative Commons license.