Socket
Socket
Sign inDemoInstall

@easily-tools/mock-server

Package Overview
Dependencies
152
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @easily-tools/mock-server

a mock server: you can config api response with typescript through web page.


Version published
Weekly downloads
12
decreased by-7.69%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Title: A Mock Server for Development

中文文档

Abstract: This document provides an overview of the mock server package, including installation, configuration, and usage instructions.

1、Installation

To install the mock server using npm, execute the following command:

npm i @easily-tools/mock-server --save-dev

Alternatively, for yarn users:

yarn add @easily-tools/mock-server -D

For pnpm, the command is:

pnpm add @easily-tools/mock-server -D

2、Configuration

A sample mock.config.json configuration is provided below:

{
  "$schema": "https://raw.githubusercontent.com/a-super-cat/dev-server/main/mock-config-schema.json",
  "serverPort": 3000,		// the mock server port, not required, default is 3000,
  "wsServerPort": 3001,		// the mock server ws port for mock server push message to mock server web
  "mockDir": "mock",		// the folder name is used to store the mock file
  "proxy": {
    "/test": {				// The prefix of the target brokered by the mock service
      "target": "http://example.com/", // support http/https
    }
  }
}

example: "http://localhost:3000/test/api/xxx" === "http://example.com/api/xxx"

3、Running the Server

To run the mock server, use the following command with npm:

npx mock

For yarn:

yarn mock

Or with pnpm:

pnpm mock

Notice: If the mock command is occupied, the alternative "mock-server" cmd can be used.


4、Usage

4.1 Install & Start

add-start.gif

4.2 Add a normal mockItem

Note: The return value configuration is a function that takes the actual request parameters (for GET requests, they are also processed as objects passed into the function). You can flexibly configure the return values based on these parameters.

useCase.gif

4.3 Add a Api with path param

Note: If the API has path parameters, use a colon at the beginning when configuring the API to mark that this position is a path parameter. In the response configuration of the scenario, you can use pathParams to obtain the actual parameters at the time of the request. It is an array of string types, and the order of the parameters in the array is the same as the order of the path parameters defined when the API is defined

with-Path-Param.gif

4.4 Automatic response

Note: If no Scene is selected, the return value of the Scene configuration that best matches the requested parameters (calculated based on the fields and values of the Scene parameters and the actual requested parameters) is returned, and if there are multiple matches, the result of the most recently configured Scene is returned

auto-Response.gif

4.5 Choose Scene

Note: If you select a scenario, when a request comes in, the return value configuration corresponding to the chosen scenario will be returned. If you click on the scenario name again, you can cancel the selection.

when-Selected-Scene.gif

4.6 Brief model

Note: You can choose the brief mode, which displays information in a condensed manner. To view the mock item with full information, click the icon on the left side of the mock item. Additionally, if you make modifications to the mock item, it will switch to the normal mode.

brief-Model.gif

4.7 Manage scene with iteration

use-Iteration.gif

4.8 Setting

Note: If you wish to create a mockItem through a real request, you need to configure it in the settings. You can choose the password encryption method and the salt. If there is no encryption, please select 'none'. At the end of the 'Login Api', you can choose whether to use header or query methods for encrypting information. In 'Auth Conf', the fields on the left side are the ones required by the system, while the fields on the right side are those required by your login interface, which are used for field mapping

​ The auth configuration is used to define the format of authentication information. If yours differs from the default, please modify it accordingly.

setting.gif

4.9 Use in project

Note: When using it in a project, you can configure the env file to send requests to the mock server in the development environment.

screenshots.gif

Contact Information:

For any issues or inquiries regarding the code, please submit an issue on the GitHub repository or contact the developer at to_great_again@outlook.com.

Keywords

FAQs

Last updated on 08 Apr 2024

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