Socket
Socket
Sign inDemoInstall

@requestly/mock-server

Package Overview
Dependencies
65
Maintainers
7
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @requestly/mock-server

- Methods: GET, POST, PUT, OPTIONS - Description - Endpoint (can be full path) (/api/v1/users) - Multiple Responses - Shuffle Response - Sequential Response - Rules in Response - Status (Any status code 2xx, 4xx) - Latency - Body - Templat


Version published
Weekly downloads
25
decreased by-7.41%
Maintainers
7
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 10 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc