Skip to content

hamzabourak/stubifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stubifier

Stub endpoints in any easy and isolated way.

Stubifier uses a Service Worker to stub endpoints at the browser level.

npm i -D stubifier

Benefits

  1. No need to run any server or modify your backend code.
  2. Works through your entire application.

Usage

The package exports a stub method that you can call anywhere in your app (preferably in your entry point file).

stub method parameters:

  1. 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.
  2. The stub endpoints (see the below example for the structure of the object that needs to be provided).

Example

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);