3

I noticed people use 2 ways of retrieving data from remote source: http.get() and http.request().

What is the difference between http.get() and http.request() method in Angular?

3
  • 3
    I'm downvoting this as not showing research effort, since this is easily found in the documentation: angular.io/api/http/Http#request Commented Oct 6, 2017 at 15:41
  • 1
    i'm sorry. Google was clueless. In general, it doenst link to the angular docs. Perhaps this qquestion will help future readers, since it ranks well. (google.com/search?q=http.get+vs+http.request+angular) Commented Oct 6, 2017 at 16:10
  • 1
    When you search for any Angular (2-4) docs or tips on Google, I strongly recommend adding -angularjs after your search terms in order to clean the results of all the non-relevant AngularJS bloating! otherwise it can be a pain to find what you want. Commented Oct 6, 2017 at 19:22

1 Answer 1

6

http.get() is just a shorthand to using http.request() with the method field of the Request argument set as RequestMethod.Get .

The same goes for the http methods named with a HTTP verb :

  • http.put()
  • http.post()
  • http.delete()
  • http.head()
  • http.patch()
  • http.options()

(with, depending on the method, some convenient other arguments as shortcut for the relevant RequestOption, such as body for http.post() )

So the actual only difference is just readability, but that's IMHO important enough to prefer these specific methods over directly using http.request()

For information, here is the relevant documentation link : https://angular.io/api/http/Http#members , a good place to start for any basic question on the meaning and syntax of the common Angular objects and methods.

Also, don't forget that Angular is Open Source, you can just search for any code of the various packages, and have a look at it!

Here is the source for http : https://github.com/angular/angular/blob/master/packages/http/src/http.ts .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.