Rules

Loading Faker.js library from jsDelivr to generate fake response payloads

Pro

Learn how to import external modules and use them in your interception rules.

In this video guide, we're going to import Faker.js from jsDelivr CDN and use it to generate fake response payloads.

Note: JS scripts and modules are only available in the Mockery Pro plan. You can check our 7-day free trial available on the Pricing page.

Code snippet used in the video:

import { faker } from 'faker';

const createUser = () => {
  return {
    id: faker.string.uuid(),
    username: faker.internet.username(),
    email: faker.internet.email(),
  };
}

export const computeBody = (req) => {
  const users = Array.from({ length: 4 }, () => createUser());
  
  return JSON.stringify(users);
}