Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between $http.get and method:'GET'

I'm using Spring Data REST and have a MySQL DB to manage my data. With AngularJS I programmed my first page and want to get data from my DB.

To get my data I know about two different ways:

$http.get('http://myURL')

and

$http({
    method:'GET'
    url:'http://myURL'
}

But where's the difference between them?

Thanks for help!

like image 485
Phil Avatar asked Dec 02 '25 09:12

Phil


2 Answers

There is no difference, $http.get('http://myURL') is just a shortcut for $http({method:'GET, url:'http://myURL'}

like image 168
WirelessKiwi Avatar answered Dec 03 '25 23:12

WirelessKiwi


  1. First way of getting the response is the short form of the second one.

  2. If you want to set some headers for the request you have to write the request via second way... that is much more clear way of writing it.

    var req = { method: 'POST', url: 'http://example.com', headers: {       'Content-Type': undefined },  data: { test: 'test' }} $http(req).then(function(){...}, function(){...});
    
like image 22
Ashish Awasthi Avatar answered Dec 04 '25 00:12

Ashish Awasthi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!