🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

github.com/mysurii/mock-server

Package Overview
Dependencies
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/mysurii/mock-server

Source
Go Modules
Version
v0.0.0-20241002133547-ce27a9515887
Version published
Created
Source

Mock Server Generator

A lightweight mock server generator in Go that allows developers to easily create mock APIs based on JSON configurations, facilitating rapid frontend development and testing without backend dependencies.

Features

  • Dynamic API Endpoints: Define API endpoints in JSON configuration files.
  • Flexible Response Handling: Return mock responses based on the defined structure in the configuration.
  • File-Based Configuration: Load payloads from JSON files for endpoints.
  • CLI Integration: Simple command-line interface to initialize and run the mock server.

Installation

To install the mock server generator, clone the repository and build the project:

git clone https://github.com/Mysurii/mock-server.git
cd mock-server-generator
go build ./cmd/cli/main.go

Usage

To run the mock server, use the following command:

./main.exe --config path/to/config.json

Or run the following command to create needed config file & example payload files

./main.exe --example

Config format

The configuration file should be in JSON format. Here is an example:

{
  "port": 8080,
  "endpoints": [
    {
      "method": "POST",
      "status": 200,
      "path": "/login",
      "jsonPath": "./mock/auth/login.json"
    },
    {
      "method": "GET",
      "status": 200,
      "path": "/users",
      "jsonPath": "./mock/users/users.json"
    },
    {
      "method": "POST",
      "status": 201,
      "path": "/users"
    },
    {
      "method": "GET",
      "status": 200,
      "path": "/users/{id}",
      "jsonPath": "./mock/users/user.json"
    }
  ]
}

Contribution

Contributions are welcome! Feel free to submit a pull request or create an issue for any enhancements or bug fixes.

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

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