@requestly/mock-server
TypeScript icon, indicating that this package has built-in type declarations

0.2.8 • Public • Published

requestly-mock-server

This Repo contains the core express server @requestly/mock-server package which powers Requestly's Cloud Mock Server.

Development

Install Dependencies

npm i

Start Server

npm start:dev

Usage with firebase-functions

Install

npm i @requestly/mock-server

Setup

import * as functions from 'firebase-functions';
import { MockServer } from '@requestly/mock-server';
import firebaseConfigFetcher from '../firebaseConfigFetcher';

const startMockServer = () => {
  const expressApp = new MockServer(3000, firebaseConfigFetcher, '/api/mockv2').app;

  return functions.runWith({ minInstances: isProdEnv() ? 1 : 0 }).https.onRequest(expressApp);
};

export const handleMockRequest = startMockServer();
class FirebaseConfigFetcher implements IConfigFetcher {
    getMockSelectorMap = (kwargs?: any) => {
        /**
        * Fetch and return mockSelectorMap from firestore
        * {
        *      mockId: {
        *          route: "",
        *          method: "",
        *      }
        * }
        */
    };
    
    getMock = (id: string, kwargs?: any) => {
        /**
        * Fetch mock details from firestore
        */
    }
}

const firebaseConfigFetcher = new FirebaseConfigFetcher();
export default firebaseConfigFetcher;

Requestly Cloud Mock Server Architechture

image

STEPS

  1. Request coming from GET https://username.requestly.dev/users
  2. Firebase Function passes the request to @requestly/mock-server
  3. @requestly/mock-server - MockSelector a. Fetches all the available mocks using IConfigFetcher.getMockSelectorMap() (Firestore in case of Requestly) b. Select mock if any endpoint+method matches the incoming request (GET /users) c. Fetch Mock using IConfigFetcher.getMock(mockId) and pass it to MockProcessor
  4. @requestly/mock-server - MockProcessor a. Process Mock - Response Rendering b. Return Response

Readme

Keywords

none

Package Sidebar

Install

npm i @requestly/mock-server

Weekly Downloads

157

Version

0.2.8

License

ISC

Unpacked Size

69.4 kB

Total Files

45

Last publish

Collaborators

  • sagarsoni7
  • nsrcodes
  • wrongsahil
  • vaibhavnigam
  • sankhachak
  • requestlyio
  • nafees87n