Skip to main content

Installation

mockforme makes it easy to set up and start mocking APIs in minutes. You can install it using NPM, Yarn, or integrate it directly via CDN—perfect for fast setup and seamless frontend testing.


Install mockforme Using Yarn

yarn add mockforme -D

Install mockforme Using NPM

npm install mockforme --save-dev

Add it as a development dependency to your project and begin simulating REST API endpoints without writing backend code.

Use mockforme via CDN (No Install Required) For quick prototyping or testing in tools like CodeSandbox, you can load mockforme directly via a CDN. We recommend using jsDelivr for stable and fast delivery.

Add the following snippet to your HTML file inside the <head> tag or before your scripts:

<script src="https://cdn.jsdelivr.net/npm/mockforme@4.0.0/dist/mockforme.client.umd.js"></script>

How to Use mockforme in a React App

Below is a working example showing how to mock API responses in a React component using mockforme.

import { useEffect } from "react";
import { mockforme } from "mockforme";

const TOKEN = "ACCESS_TOKEN"; // Replace with your actual mockforme token
mockforme(TOKEN).run();

export default function YourComponent() {
useEffect(() => {
fetch("https://api.restful-api.dev/objects")
.then((res) => res.json())
.then((res) => {
console.log(res);
});
}, []);

return (
<div className="App">
<h1>Hello mockforme</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}