AI Hints
Home›Angular Tutorial›Talking to a Server, HttpClient and GET Requests
Angular · Lesson 91 of 120

Talking to a Server

HTTP.

⏱ 2 min read▶ Video at 1:49:28🎓 Free
Watch this lesson in the Angular courseWatch on YouTube ↗Full Angular course

So far, our books have been written into the code. A real shop keeps its books on a server, in a database. Our app has to ask the server for them.

  • Books in the code
  • Real books on a server
  • Ask the server

A request and a response

The app sends a request, to an address on the server, like slash api slash books. The server finds the data. It sends back a response, with a status code, and the data, as JSON. Then the app shows it.

  1. App: request
  2. GET /api/books
  3. Server finds the books
  4. Response: 200 + JSON
  5. App shows them

HTTP methods

Get reads data. Post creates something new. Put updates something that exists. And delete removes it. Together, these make a REST API.

MethodMeaningExample
GETreadGET /api/books
POSTcreatePOST /api/books
PUTupdatePUT /api/books/2
DELETEremoveDELETE /api/books/2

Status codes

Every response has a status code. Two hundreds mean success. Four hundreds mean the request was wrong, like four oh four, not found. And five hundreds mean the server itself failed.

keyvalue
200, 201, 204success
400, 404a bad request, not found
500the server failed
Bodyusually JSON

Summary

Apps send requests, with methods like get, and post, and servers send back responses, with a status code, and JSON. Next, Angular's HTTP client.

Key takeaways
  • Request, response
  • GET, POST, PUT, DELETE
  • Status codes
Next up: HttpClient — Angular talks HTTP