In almost any application that we work with, the first important thing to do is to deal with data, loads and loads of data. And this data which resides on the server is dealt with by the use of HTTP operations. We perform HTTP GET and POST operations to work with that data.
Now, in a real application, this data is stored on the server and received through API. However, for testing purposes, instead of using a real server, we can actually fake the back-end server.
The different ways to use a fake back-end server are:
Create a file, hard-code the data, and return this data.
Create a local JSON file and use it
Use Angular in-memory-web-api
The best out of all to perform CRUD operations for development and testing purposes, is to use Angular in-memory-web-api. Using this, we can actually simulate a server and return mock data with the HTTP requests.
This angular-in-memory-web-api is not a part of Angular Core but it is provided as a service in the Angular documentation. This will now send the HTTP requests to the local in-memory data store in place of the remote server and make our task a lot more easier.
The main purpose of this blog post is to put light on using angular-in-memory-web-api to produce a working CRUD application with Angular. By the end of this blog post, you should be able to create, read, update, and delete the data .
To start, the very first task is to install angular-in-memory-web-api using the command:
npm install angular-in-memory-web-api — save-dev
The save dev flag is used here to save this dependency that we will use for the development purpose.
Once done, you’ll be able to see it in the dependencies inside your package.json file.
Read the full article here: