Stub endpoints in any easy and isolated way.
Stubifier uses a Service Worker to stub endpoints at the browser level.
npm i -D stubifier
- No need to run any server or modify your backend code.
- Works through your entire application.
The package exports a stub method that you can call anywhere in your app (preferably in your entry point file).
stub method parameters:
- The Service Worker url, the service worker file (stubifierServiceWorker.js) should be copied in a folder (preferably the root of your app) inside your web application that can be accessed by the borwser.
- The stub endpoints (see the below example for the structure of the object that needs to be provided).
import { stub } from 'stubifier';
const stubs = [{
// !! this url should be a 'sub' url of the Service Worker url
url: 'api/projects/*/tasks', // Relative endpoint url, * can be used as a 'jocker'
data: [
{
Id: 1,
Name: 'First task',
},
{
Id: 2,
Name: 'Second task',
},
],
}];
stub('../stubifierServiceWorker.js', stubs);