Don't understand - Tour of heroes HTTP

193 Views Asked by At

I'm new to Angular and I started by doing the tutorial: "Tour of heroes". I didn't understand the HTTP part and I hope that somebody could explained to me. At some point they switched the mock-heroes with an InMemoryDataService and I understood that this service will provide me all the heroes. I did not understand, what is the connection between the service and heroesUrl? I don't see a connection between heroesUrl and InMemoryDataService

1

There are 1 best solutions below

0
rveerd On BEST ANSWER

The InMemoryDataService is for testing only. It allows you to test HTTP request without setting up a HTTP server with a webservice.

The InMemoryDataService intercepts HTTP requests in the browser and replies as if the request went to the server.

It only intercepts request to URLs that begin with the "base path", which by default is "api".

In the createDb() function, you define a dataset for the service. The sample uses a dataset with only one "collection" named "heroes".

When you do a HTTP request to "api/heroes", the service will intercept the request (because it starts with "api") and returns the "heroes" collection.