Fireship · @fireship

Angular HTTP Client Quick Start Tutorial

Uploaded October 9, 2017 · Length 9:56

Angular HTTP Client Quick Start Tutorial

Summary

This tutorial teaches how to use Angular's HTTP client to interact with RESTful APIs, including making GET, POST, and other requests, and handling errors.

  • angular http client tutorial
  • restful api tutorial
  • angular http requests
  • angular error handling

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    mastering the basics of angular's HTTP

  2. 0:02

    module well open up the door to interact

  3. 0:04

    with thousands of exciting web-based

  4. 0:06

    api's by the end of this lesson you'll

  5. 0:08

    have the basic tools you would need to

  6. 0:09

    do things like request weather data

  7. 0:11

    stock quotes nutrition facts as well as

  8. 0:13

    interact with major platforms like

  9. 0:15

    Facebook Twitter and Amazon Web Services

  10. 0:18

    the one thing these products all have in

  11. 0:19

    common is that they provide a restful

  12. 0:21

    api that you can consume from your

  13. 0:23

    angular app Before we jump into the code

  14. 0:25

    let's quickly look at what a restful api

  15. 0:27

    is and how communication works between

  16. 0:29

    the client and the server so here we

  17. 0:32

    have a client on the left and a server

  18. 0:34

    on the right rest is simply a way for

  19. 0:36

    these two parties to communicate in a

  20. 0:38

    standardized way when the client makes a

  21. 0:40

    request it's going to use a specific

  22. 0:42

    verb or method to interact with the

  23. 0:44

    server first we'll go ahead and make a

  24. 0:46

    get request this tells the server that

  25. 0:48

    we only want to retrieve data and we're

  26. 0:50

    not going to modify it in any way the

  27. 0:52

    server will respond with the status code

  28. 0:54

    as well as the data that was requested

  29. 0:55

    if it was a successful request it should

  30. 0:58

    be a 200 level response but if the

  31. 1:00

    request wasn't valid it should be a 400

  32. 1:02

    or 500 level error response a 400

  33. 1:05

    response generally means the client

  34. 1:07

    screwed something up and a 500 level

  35. 1:09

    response generally means there was an

  36. 1:11

    error on the server itself if we send a

  37. 1:13

    post request we're telling the server

  38. 1:15

    that we intend to create new data when

  39. 1:17

    you send a post request you also send

  40. 1:19

    that data payload with it which is the

  41. 1:21

    data you intend to save on the server

  42. 1:23

    after the server successfully saves it

  43. 1:25

    it should respond with a 201 success

  44. 1:27

    message this time saying that the

  45. 1:29

    resource was created in addition to

  46. 1:31

    getting post you also have other verbs

  47. 1:33

    such as put patch and delete they all

  48. 1:36

    work in a similar way just conveying a

  49. 1:38

    slightly different message for what you

  50. 1:39

    intend to do on the server and that's

  51. 1:42

    basically the gist of how rest works

  52. 1:43

    from a very high level now let's start

  53. 1:46

    retrieving data from a restful endpoint

  54. 1:47

    using angular for this lesson I'm going

  55. 1:50

    to be working from a stack blitz project

  56. 1:52

    this allows me to include a link in the

  57. 1:54

    description where you can run this code

  58. 1:55

    and fork it for yourself the first thing

  59. 1:58

    we're going to do is go into the app

  60. 1:59

    module and import the HTTP client module