Mimic Server(In-Memory Web Api)

Nowadays, most computer users retrieve the data they want by executing HTTP service to the server. However, in some scenarios you might not want to do such remote server connection. You just want to have a simple test. There are many fronted-side libraries which allow you to mimic http service. In Angular, there is a package, ‘in-memory web api’ that allows you to achieve this purpose. After you install this package, your http method will be intercepted by memory web api and do the response.

        If you want to install this package, you need DOS and enter the path where you like and do npm command.

        You then need to import two packages HttpClientModule and InMemoryWebApiModule to AppModule.

        Call forRoot() method to receive InMemoryDataService the service which is used to initialize memory database

The diagram below shows AppData ts. To mimic remote http service, you have to implement InMemoryDbService to the class and create createDb() method.

Product class

Remember to import AppData to AppModule

Then use rxjs library to perform http get method to get product list data.

Html page

The above content manifests how to use the package (In-Memory Web Api) to mimic data query process. Other than the query procedure, the action of data creation, modification and deletion can also be done by this package.