• Mock Server


    下载地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/

    此处使用standalone的方式,不使用api用法

    启动方式(单独配置文件启动):java -jar (jar包位置) (协议) -p (端口) -c 配置文件地址

    1 全局配置文件

    [
      {"context":"/path1", "include":"startup.json"},
      {"context":"/path2", "include":"startup2.json"}
    ]

    这儿的启动方式有变化, 启动方式(全局配置文件启动):java -jar (jar包位置) (协议) -p (端口) -g 配置文件地址,访问要加上context的utl,如访问startup1.json中的访问方法,

    访问路径为:http://localhost:8888/path1/demo/noparam

    以下是一些常见的方法

    config.json

    [
      {"context":"/path1", "include":"startup.json"},
      {"context":"/path2", "include":"startup2.json"}
    ]

    startup.json

    [
      {
        "description": "这是一个get请求",
        "request": {
          "uri": "/demo",
          "method": "get",
          "queries": {
            "name": "lww",
            "age": "34"
          }
        },
        "response": {
          "text": "返回的方式为文本",
          "headers":{
            "Content-Type":"text/html;charset=gbk"
          }
        }
      },
      {
        "description": "这是一个不带有请求参数的get请求",
        "request": {
          "uri": "/demo/noparam",
          "method": "get"
        },
        "response": {
          "text": "这是不带有请求参数的get请求",
          "headers": {
            "Content-Type":"text/html;charset=gbk"
          }
        }
      },
      {
        "description": "这是一个post的请求",
        "request": {
          "uri": "/demo/postNoParam",
          "method": "post"
        },
        "response": {
          "text": "这是一个post请求,不带有参数",
          "headers": {
            "Content-Type":"text/html;charset=gbk"
          }
        }
      },
      {
        "description": "这是一个带有的参数的post请求",
        "request": {
          "uri": "/demo/postwithparam",
          "method": "post",
          "forms": {
            "name": "lww",
            "age": "45"
          }
        },
        "response": {
          "text": "这是一个post请求,并且带有参数",
          "headers": {
            "Content-Type":"text/html;charset=gbk"
          }
        }
      },
      {
        "description": "这是一个get请求,带有cookie信息",
        "request": {
          "uri": "/demo/withCookie",
          "method": "get",
    
          "cookies": {
            "hello": "lww"
          }
    
        },
        "response": {
          "headers": {
            "Content-Type":"text/html;charset=gbk"
          },
          "text": "这是一个带有cookie信息的get请求"
        }
      },
      {
        "description": "这是一个带有cookie信息的post请求",
        "request": {
          "uri": "/demo/postwithcokie",
          "method": "post",
          "cookies": {
            "hello": "lww"
          },
          "json": {
            "name": "lww",
            "age": "45"
          }
        },
        "response": {
          "text": "这是一个带有cookie信息的post请求",
          "headers": {
            "Content-Type":"text/html;charset=gbk"
          }
        }
      },
      {
        "description": "这是一个带有返回状态码的请求",
        "request": {
          "method": "get",
          "uri": "/demo/withstatus"
        },
        "response": {
          "json": {
            "lww": "33333",
            "age": "45"
          },
          "status": "200",
          "headers": {
            "Content-Type":"text/html;charset=gbk"
          }
        }
      },
      {
        "description": "带有headers信息的请求,post与get一致",
        "request": {
          "uri": "/demo/withheaders",
          "method": "get",
          "headers": {
            "content-type": "application/json"
          }
        },
        "response": {
          "text": "带有headers的请求"
        }
      },
      {
        "description": "重定向",
        "request": {
          "uri": "/demo/cdx"
        },
        "redirectTo": "/demo/tocdx"
      },
      {
        "description": "重定向到这个",
        "request": {
          "uri": "/demo/tocdx"
        },
        "response": {
          "text": "到这儿",
          "headers": {
            "Content-Type":"text/html;charset=gbk"
          }
        }
      },
      {
        "description": "上传文件",
        "request": {
          "uri": "/demo/file"
        },
        "response":{
          "file": "C:\Users\lwf\Desktop\test-output\report.html"
        }
    
      }
    
    ]
    

      startup2.json

    [
      {
        "description": "这是delete请求",
        "request": {
          "method": "delete",
          "uri": "/demo/del"
        },
        "response": {
          "status": "200"
        }
      },
      {
        "description": "这是一个put方法",
        "request": {
          "uri": "/demo/put",
          "method": "put"
        },
        "response": {
          "status": "200"
        }
      },
      {
        "description": "xml",
        "request": {
          "uri": "/demo/xml",
          "text": {
            "xml": "<request><parameters><id>1</id></parameters></request>"
          }
        },
        "response": {
          "status": "200"
        }
      }
    ]

    更多查看:https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md

    以上是我暂时能想到的常用的请求

    网上看教程moco是支持热部署的, 但是不知道是因为我下载的版本太低还是怎么回事并不能进行热部署

  • 相关阅读:
    创建共享内存函数CreateFileMapping()详解
    窗口类、窗口类对象与窗口
    ubuntu中文版切换为英文后字体变化问题解决
    安装ubuntu12.04LTS卡住以及花屏问题
    时钟周期、振荡周期、机器周期、CPU周期、状态周期、指令周期、总线周期、任务周期
    波特率
    myod
    mycp
    20165226 2017-2018-2《Java程序设计》课程总结
    2017-2018-2 20165226 实验五《网络编程与安全》实验报告
  • 原文地址:https://www.cnblogs.com/sailfan/p/10427939.html
Copyright © 2020-2023  润新知