github.com/kumasuke120/mockuma@v1.1.9/README.md (about)

     1  # MocKuma [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Release](https://img.shields.io/github/release/kumasuke120/mockuma/all.svg)](https://github.com/kumasuke120/mockuma/releases/latest) [![Build Status](https://api.travis-ci.org/kumasuke120/mockuma.svg?branch=dev)](https://travis-ci.org/kumasuke120/mockuma) [![codecov](https://codecov.io/gh/kumasuke120/mockuma/branch/dev/graph/badge.svg)](https://codecov.io/gh/kumasuke120/mockuma)
     2  
     3  [English | [中文](README_CN.md)]
     4  
     5  MocKuma is an http mocking server. It reads command-like json mapping configuration file, generating
     6  corresponding mock APIs dynamically.
     7  
     8  Front/back end developers may use this tool to mock RESTful APIs, helping developments and unit testings;
     9  Tester may also use this tool with its command-like mapping configuration, writing mock APIs to match the parameters
    10  and testing it.
    11  
    12  ### Features
    13  - maps responses based on requests' parameters/headers
    14  - reloads automatically mappings when changed
    15  - renders multiple mappings with user-defined templates and variables 
    16  - supports references static files
    17  - supports redirects and forwards
    18  
    19  
    20  ## Installation
    21  Executes the following command to install in your environment:
    22  ```
    23  $ go get -u github.com/kumasuke120/mockuma/cmd/mockuma
    24  ```
    25  
    26  You may also click [here](https://github.com/kumasuke120/mockuma/releases) to download an executable file of the latest
    27  release version if you don't own the Go development environment or if you wanna do it quickly.
    28  
    29  
    30  ## Quick Start
    31  
    32  1. Makes sure `$GOPATH\bin` has been included to your environment variable `$PATH`;
    33  2. Creates a new file called `mockuMappings.json` with its content as below:
    34  ```json
    35  [
    36    {
    37      "uri": "/",
    38      "method": "GET",
    39      "policies": [
    40        {
    41          "when": { "params": { "lang": "cn" } },
    42          "returns": {
    43            "headers": { "Content-Type": "text/plain; charset=utf-8" },
    44            "body": "你好,世界!"
    45          }
    46        },
    47        {
    48          "returns": {
    49            "headers": { "Content-Type": "text/plain" },
    50            "body": "Hello, World!"
    51          }
    52        }
    53      ]
    54    }
    55  ]
    56  ```
    57  3. Starts the MocKuma with the following command:
    58  ```
    59  $ mockuma
    60  ```
    61  4. Then you could access [http://localhost:3214/](http://localhost:3214/) or 
    62  [http://localhost:3214/?lang=cn](http://localhost:3214/?lang=cn) to check out the result. 
    63  
    64  #### Command-Line Arguments
    65  Although you could run MocKuma directly like the example above, MocKuma provides a series of command line arguments:
    66  
    67  1. `-mapfile=<filename>`: the path to the MockuMappings mapping configuration file, supports both relative and absolute path. 
    68  Under the default circumstance, MocKuma will find a configuration file called `mockuMappings.json`, 
    69  `mockuMappings.main.json` or `main.json` in the current working directory, reading and loading the file.
    70  Specifically, the working directory of MocKuma will be set to the directory in which the mapfile resides if you specify it manually;
    71  2. `-p=<port_number>`: the port number on which the MocKuma listens, the default value is 3214;
    72  3. `--version`: views the version information of MocKuma.
    73  
    74  #### More Examples
    75  You could click [here](example) to see more examples.