Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Angular 2 RC angular2-in-memory-web-api?

Tags:

angular

What is angular2-in-memory-web-api? I've seen references to it in the angular.io documentation but my code seems to work without it.

like image 859
Mark Avatar asked Jul 06 '16 13:07

Mark


Video Answer


2 Answers

It's used for demos only:

For example the get heroes scenario would work without webapi, just loading demo data from JSON file, but we want to save data too. We can't save changes to a JSON file. We need a web API server.

The in-memory web api is not part of the Angular core. It's an optional service in its own angular2-in-memory-web-api library that we installed with npm (see package.json) and registered for module loading by SystemJS (see systemjs.config.js)

The in-memory web API gets its data from a custom application class with a createDb() method that returns a map whose keys are collection names and whose values are arrays of objects in those collections.

like image 155
null canvas Avatar answered Oct 13 '22 12:10

null canvas


Here the Javadoc from the InMemoryDataService on Github:

Simulate the behavior of a RESTy web api backed by the simple in-memory data store provided by the injected InMemoryDataService service. [...]

You can use the API to create a demo application in Angular2. The service provides an API which let you simulate a REST-API. It's only an optional package and your app will work without it.

like image 7
muetzerich Avatar answered Oct 13 '22 12:10

muetzerich