Member-only story
How to Mock a Backend Server with Angular In-Memory Web API
A detailed tutorial with source code sample and cats

I recently started working on an Angular project where the set-up of the backend had been delayed. While the APIs were completely specified, the development was running late. However, I still needed to start working on that Angular application. We needed a good way to simulate the interaction with the backend server.
Hard-coding data is bad
Without thinking too much about it, we could honestly have started working with hard-coded data. Then, once the APIs were ready, we could have plugged our application into it. This approach is not the best, here is why :
- It takes some work to set it up. If you’re working with a simple GET call, reading your data will be easy. But what if you want to update data, add some authentication HTTP headers, or even see what happens when the API is slow? Sure, you can do all of that manually. But that is a lot of effort to put in while not working on the actual features of the application.
- The dependency on the backend API is still strong. Our goal is to make that dependency as small as possible. Then, as soon as the actual API is ready to be integrated, we could do it without expecting too many surprises…