๐ŸŒ
BrowserStack
browserstack.com โ€บ home โ€บ guide โ€บ dummy apis for react apps: a complete guide
Dummy APIs for React Apps: A Complete Guide | BrowserStack
September 17, 2025 - In practice, Dummy APIs are set up to provide predictable responses for specific endpoints, such as /users or /products. This allows React applications to make API calls, render data, and test flows without depending on a live server.
๐ŸŒ
Mockoon
mockoon.com โ€บ tutorials โ€บ react-api-call-and-mocking
Mockoon - Call a mock API from your React application
In Mockoon, create a GET /posts API endpoint that returns an array of blog posts: You can use the following JSON as the body returned by the endpoint: ... Note that your fake mock server will be available at the following URL: http://localhost:3000. It is the URL we will need to use in our React component.
๐ŸŒ
JSONPlaceholder
jsonplaceholder.typicode.com
JSONPlaceholder - Free Fake REST API
JSONPlaceholder is a free online REST API that you can use whenever you need some fake data.
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ need help to create a dummy api
r/reactjs on Reddit: Need Help to create a dummy api
April 27, 2023 -

I have design of a dashboard and and i wanna create a simple dummy api which contains all these data which are being shown in this dashboard and and there line chart in that dashboard which needs to be interactive with data of that dummy api

๐ŸŒ
GitHub
github.com โ€บ topics โ€บ dummy-api
dummy-api ยท GitHub Topics ยท GitHub
Revolutionize your development workflow with our customizable dummy API. ... react-router styled-components reactjs react-redux axios reactstrap dummy-api react-paginate react-slick redux-toolkit not-found-page
๐ŸŒ
Miragejs
miragejs.com โ€บ quickstarts โ€บ react-native โ€บ development
Mock API Requests in React Native with Mirage โ€ข Mirage JS
At the top of App.js, import Server from Mirage, create a server, and start mocking out API endpoints that your code needs: import React from "react" import { Text, View } from "react-native" import { createServer } from "miragejs" if (window.server) { server.shutdown() } window.server = createServer({ routes() { this.get("/api/movies", () => { return { movies: [ { id: 1, name: "Inception", year: 2010 }, { id: 2, name: "Interstellar", year: 2014 }, { id: 3, name: "Dunkirk", year: 2017 }, ], } }) }, }) export default function App() { let [movies, setMovies] = React.useState([]) React.useEffect(() => { fetch("/api/movies") .then((res) => res.json()) .then((json) => setMovies(json.movies)) }, []) return ( <View> {movies.map((movie) => ( <Text key={movie.id}> {movie.name} ({movie.year}) </Text> ))} </View> ) }
๐ŸŒ
DEV Community
dev.to โ€บ roshan_100kar โ€บ display-dummy-api-json-data-to-a-table-in-react-js-3702
Display Dummy API JSON data to a table in React JS - DEV Community
September 4, 2022 - Hello There In order to Display Dummy API data in table form using react js you have knowledge about... Tagged with react, api, javascript, json.
๐ŸŒ
Pluralsight
pluralsight.com โ€บ tech insights & how-to guides โ€บ tech guides & tutorials
Creating a Mock API in React | Pluralsight
The db.json file will act as your data source. There, you will define what data you want to retrieve from your mock API. This is where you define the sample employees and their various details as outlined earlier in the design. The first property, employees, on the JSON file is used to define the name of the endpoint.
๐ŸŒ
Apidog
apidog.com โ€บ blog โ€บ mock-rest-api-from-react
How to Use Mock Data in React.js with APIDog
July 28, 2025 - By using tools like Apidog, developers can simulate API responses, enabling efficient development and testing. This guide will walk you through the process of using mock data in your React.js projects with Apidog, ensuring smooth development even when backend services are unavailable.
Find elsewhere
๐ŸŒ
Robin Wieruch
robinwieruch.de โ€บ react-mock-data
How to mock data in React with a fake API
In this tutorial we will implement use JavaScript fake API with mock data from a pseudo backend to create our frontend application with React. Often this helps whenever there is no backend yet and you need to implement your React frontend against some kind of realistic data.
๐ŸŒ
GitHub
github.com โ€บ restuwahyu13 โ€บ react-fakers
GitHub - restuwahyu13/react-fakers: React-Fakers is a collection of dummy data for application development testing
React-Fakers is a collection of dummy data for application development testing - restuwahyu13/react-fakers
Starred by 8 users
Forked by 5 users
Languages ย  JavaScript 98.7% | HTML 1.3% | JavaScript 98.7% | HTML 1.3%
๐ŸŒ
Harvey Delaney
blog.harveydelaney.com โ€บ setting-up-a-mock-api-for-your-front-end-react-project
Setting up a Local Mock API for your Front-end (React) Project
November 5, 2020 - In this article, I'm going to cover how I create own mock APIs that allow my frontend applications to run without any other external dependencies! For this article, I'm using React and used Create React App to create the project.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ article โ€บ crud-operations-with-fake-apis-in-react
CRUD Operations With Fake APIs In React
December 26, 2022 - In this article, we are going to demonstrate CRUD operations using JSON server mock APIs in react.
๐ŸŒ
GitHub
github.com โ€บ typicode โ€บ json-server
GitHub - typicode/json-server: Get a full fake REST API with zero coding in less than 30 seconds (seriously) ยท GitHub
Using React โš›๏ธ and tired of CSS-in-JS? See MistCSS ๐Ÿ‘€ ยท npm install json-server ยท Create a db.json or db.json5 file ยท
Starred by 75.6K users
Forked by 7.3K users
Languages ย  JavaScript 91.7% | HTML 8.3%
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ the best approach to have a mock api in reactjs and toggle between the real api calls and the fake one?
r/reactjs on Reddit: The best approach to have a mock API in ReactJS and toggle between the real API calls and the fake one?
October 7, 2020 -

Hello, I'm starting to develop a web application using React as my frontend, I'm also coding the backend API using Django.

I was wondering what is the recommended method to create a mock API calls in React so I can focus on my frontend first without having to constantly update my backend API.

Also, It would be nice if I could set some sort of variable toggle so I can quickly switch between using the real backend API and the mock API.

I'm using Axios to make my API calls.

Any suggestions?

Thanks!

Top answer
1 of 3
3
I started using Mock Service Worker recently: https://mswjs. It runs a Service Worker in the browser that intercepts network requests, and then returns mocked data. It only intercepts requests you have specified. You only need a single flag in your application to say whether the Service Worker should be included. e.g. on Production, exclude it, locally, include it. This is great as all the code relating to your API calls stays the same, and you still see the requsts in the Browser's Network tab. One of your handlers may look like this: rest.post('/login', (req, res, ctx) => { const { username } = req.body if (username === 'simulate-fail-user') { // return an error return res( ctx.status(400), ctx.text('this user does not exist') ) } return res( ctx.json({ username, firstName: 'John' }) ) }) You are telling the Service Worker to intercept any requests to /login, and you can determine what the response should be. Essentially you are also mocking the server code here. You are saying, if the username is 'simular-fail-user', return an error. This allows you to easily test the error paths in your application. Furthermore, this library can also be used when running your test suites, so there is no need to mock your API calls during your unit/integration tests. I originally found out about it from this blog: https://kentcdodds.com/blog/stop-mocking-fetch/
2 of 3
1
Symulate does exactly what you're asking for. Just define typed endpoints in your frontend with the symulate sdk, it will just return the data you need when requested. The data is AI generated so it looks pretty realistic compared to Faker.js etc.
Top answer
1 of 4
21

By default jest.mock calls are hoisted by babel-jest...

...this means they run before anything else in your test file, so any variables declared in the test file won't be in scope yet.

That is why the module factory passed to jest.mock can't reference anything outside itself.


One option is to move the data inside the module factory like this:

jest.mock("../utils/userUtils", () => {
  const users = [ /* mock users data */ ];
  return {
    getUsers: jest.fn(() => Promise.resolve(users))
  };
});
jest.mock("../utils/roleUtils", () => {
  const roles = [ /* mock roles data */ ];
  const usersWithRoles = [ /* mock usersWithRoles data */ ];
  return {
    getRolesWithUsers: jest.fn(() => Promise.resolve(usersWithRoles)),
    getRoles: jest.fn(() => Promise.resolve(roles))
  };
});

Another option is to mock the functions using jest.spyOn:

import * as userUtils from '../utils/userUtils';
import * as roleUtils from '../utils/roleUtils';

const users = [ /* mock users data */ ];
const roles = [ /* mock roles data */ ];
const usersWithRoles = [ /* mock usersWithRoles data */ ];

const mockGetUsers = jest.spyOn(userUtils, 'getUsers');
mockGetUsers.mockResolvedValue(users);

const mockGetRolesWithUsers = jest.spyOn(roleUtils, 'getRolesWithUsers');
mockGetRolesWithUsers.mockResolvedValue(usersWithRoles);

const mockGetRoles = jest.spyOn(roleUtils, 'getRoles');
mockGetRoles.mockResolvedValue(roles);

And another option is to auto-mock the modules:

import * as userUtils from '../utils/userUtils';
import * as roleUtils from '../utils/roleUtils';

jest.mock('../utils/userUtils');
jest.mock('../utils/roleUtils');

const users = [ /* mock users data */ ];
const roles = [ /* mock roles data */ ];
const usersWithRoles = [ /* mock usersWithRoles data */ ];

userUtils.getUsers.mockResolvedValue(users);
roleUtils.getRolesWithUsers.mockResolvedValue(usersWithRoles);
roleUtils.getRoles.mockResolvedValue(roles);

...and add the mocked response to the empty mock functions.

2 of 4
8

Don't mock the tool making API calls; stub the server responses. Here's how I would re-write your test using an HTTP interceptor called nock.

import "jest-dom/extend-expect";
import React from "react";
import { render, waitFor } from "react-testing-library";
import UserTable from "../UserTable";

const users = [
  {
    name: "Benglish",
    iden: "63fea823365f1c81fad234abdf5a1f43",
    roles: ["eaac4d45c3c41f449cf7c94622afacbc"]
  }
];

const roles = [
  {
    iden: "b70e1fa11ae089b74731a628f2a9b126",
    name: "senior dev"
  },
  {
    iden: "eaac4d45c3c41f449cf7c94622afacbc",
    name: "dev"
  }
];

const usersWithRoles = [
  {
    name: "Benglish",
    iden: "63fea823365f1c81fad234abdf5a1f43",
    roles: [
      {
        iden: "eaac4d45c3c41f449cf7c94622afacbc",
        name: "dev"
      }
    ]
  }
];

describe("<UserTable/>", () => {
  it("shows users", async () => { // <-- Async to let nock kick over resolved promise
    nock(`${server}`)
      .get('/users')
      .reply(200, {
        data: users
      })
      .get('/usersWithRoles')
      .reply(200, {
        data: usersWithRoles
      })
      .get('/roles')
      .reply(200, {
        data: roles
      });
    const { queryByText } = render(<UserTable />);

    await waitFor(() => expect(queryByText("Billy")).toBeTruthy()); // <-- Is this supposed to be "Benglish"?
  });
});

Now your test suite is unaware of how you get the data, and you don't have to maintain complicated mocks. Check out a blog post I wrote Testing Components that make API calls for a deeper dive.

๐ŸŒ
Medium
medium.com โ€บ @ahsan-ali-mansoor โ€บ how-to-create-fake-apis-for-your-react-app-typescript-7ecc0dbf8b39
How to create fake APIs for your React App (TypeScript) | by Ahsan Ali Mansoor | Medium
January 23, 2022 - How to create fake APIs for your React App (TypeScript) When it comes to prototyping, we want to get it done quickly. Therefore, weโ€™ll look at how we can accomplish this. We can write the APIs that โ€ฆ
๐ŸŒ
Reqres
reqres.in
ReqRes: Free REST API for Testing, Prototyping & QA ...
ReqRes is the frontend-first backend you call with fetch(). Projects bundle collections, app users, logs, and automations-no backend code required.
๐ŸŒ
DummyJSON
dummyjson.com
DummyJSON - Free Fake REST API for Placeholder JSON Data
DummyJSON provides a free fake REST API with placeholder JSON data for development, testing, and prototyping. Access realistic data quickly for your projects.
๐ŸŒ
GitConnected
levelup.gitconnected.com โ€บ how-to-create-a-mock-api-server-and-use-it-for-making-api-calls-in-react-fc801a998015
How to Create a Mock API Server and Use It For Making API Calls in React | by Kunal Nalawade | Level Up Coding
March 6, 2023 - ... Now, for the mock server, we are not going to create one on our own. Weโ€™ll use the npm package json-server. This package creates a mock REST API for you to test your API calls.