Mock APIs: Different Techniques for React and Angular

Mock APIs: Different Techniques for React and Angular

Different techniques you can use for API Mocking when developing Angular and React frontend features

In web development, specialization improves productivity. In line with this, we can find developers who specialize in frontend or backend. However, splitting work and combining them to deliver functionality isn’t that easy when it comes to development. But the good news is, there are proven techniques that work in these circumstances.

To improve productivity, frontend developers can start their work by hardcoding values or mocking the backend API.

Mocking the backend is especially useful when delivering or  sharing components as independent building blocks, using Bit ( Github). As mentioned before, you don’t want to deliver front-end features without testing them first, but at the same time, you don’t want to be coupled to other developers or teams.

This article will show how you can begin frontend development (and even deliver it independently) by mocking the backend.

Here is a list of topics I’m going to direct your focus towards.

  • Why Mock APIs?
  • What should be mocked? — A list of common modules suitable for mocking
  • JavaScript Libraries Available for Mocking
  • Mock React/Angular apps with JSON server
  • Angular CRUD backendless application with interceptors
  • React CRUD backendless application with Axios mock adapter
  • React CRUD backendless application with JSON server and Mirage JS

All the examples explained in this article have the same logic with the same components and one HTTP service for calling CRUD endpoints. The only difference between each example application would be the way of mocking.You can find the links to full source code alongside the examples.

Why Mock APIs?

Let’s start our discussion with “Why should we use Mock API.” To begin with, have a look at the following benefits of Mock APIs.

  • Frontend developers and backend developers can work in parallel, hence fast development.
  • UI/UX developers can start only the required backend mock APIs
  • The frontend can act as a standalone application during development without any backend API dependencies.
  • Enable offline development
  • Easy to demo
  • The mock API can easily be replaced with the Real API once it’s ready.

angular mock-api javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Top 10 API Security Threats Every API Team Should Know

Learn what are the most important API security threats engineering leaders should be aware of and steps you can take to prevent them

An API-First Approach For Designing Restful APIs | Hacker Noon

I’ve been working with Restful APIs for some time now and one thing that I love to do is to talk about APIs.

Public ASX100 APIs: The Essential List

The method used for this initial research was to obtain a list of the ASX100 (as of 18 September 2020). Then work through each company looking at the following

Angular Rest API Mock with Deno

This article is a step-by-step, practical guide focused on creating a Rest API, with full CRUD actions, for an Angular application. I will not cover too many details about Deno though, as it would make the post way too long, and there are already plenty of good introductions to Deno already. How to decouple your client app from network responses (Angular Rest API Mock with Deno)

What Are Good Traits That Make Great API Product Managers

What is API product management and what can you be doing to be a better API product manager — get aligned with SaaS and enterprise software requirements. This guide lays out what is API product management and some of the things you should be doing to be a good product manager.