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.

Integrate with Vanilla Javascript

Use mockforme via CDN (No Install Required)

For quick prototyping or integrate with Vanilla Javascript, 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@latest/dist/mockforme.client.umd.js"></script>

<script>
mockforme().run();
</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.

YourComponent.js
import { useEffect } from "react";

import { mockforme } from "mockforme";

mockforme().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>
);
}