Moco Server jar package for easy API Setup

Source: Internet
Author: User

In fact, the so-called API building is to use a Moco server jar package, through a simple JSON file to achieve simulation test Api,jar package 0.11.0 0.10.2first, the basic configuration1. Download the jar package: Create a new folder, rename the downloaded jar package and drag it to the changed folder (the jar package name is too long to look uncomfortable when using the command line); 2. Create a new request folder to hold the requested JSON file    The new response folder is used to store the JSON file for the response.     3, new Configs.json file, this file is used to configure the API, which refers to the need to configure the server request file. After completion, my file framework is as follows: (Readme.md used to store the note, optional) 4, use: (Of course, there is no specific configuration JSON text, later on the code) terminal:
        1, Cd/users/sunjianfei/ios development/local\ server\-\ Api         //Jar Package folder        2, Java- Jar moco-0.11. 0 8080 -G Configs.json

The terminal displays the following information, the service opened successfully:Ii. Examples of Post,get requests1. I have created two JSON files in request, as follows: Posttest.json:
 [//Validation Successful    {         "Request":{              "Method":"Post",              "URI":"/postmethod",              "Headers":{                      "Content-type":"Application/json"                          },              "JSON":{                      "name":"Zhangsan",                      "Password":"123456"                      }        },         "Response":{              "file":"Response/post/posttest_response.json"                  }    }, //validation failed (parameter error or no parameter)    {        "Request":{                "Method":"Post",                "URI":"/postmethod"                },        "Response":{                "text":"default"                }     }  ]
View Code

Gettest.json:
[//Validation Successful  {  "Request":{  "Method":"Get",  "URI":"/gettest",  "Queries":{"param1":"1","param2":"2"}   },   "Response":{"file":"Response/get/gettest_suc_response.json"}  }, //validation Failed  {  "Request":{"Method":"Get","URI":"/gettest"},   "Response":{"file":"Response/get/gettest_fail_response.json"}   } ] 
View Code

2, Configuration Configs.json[{ "include": "Request/gettest.json" }, { "include": "Request/posttest.json" }, ]3, the Response folder under the new need to return the error message JSON file, JSON filename and need to return the name of the file corresponding, JSON as follows: (according to the requirements, can be changed arbitrarily)[ { " status " :" fail "  " Status_code ":" 001 ", "Error_message":"Information error", "Data": {}  }]4, according to the above method to start the server, I was in the Paw and simulator test on the real machine, the PAW request is as follows: third, the use of attention
1, headers for application/JSON type, followed by a JSON"Headers":{"Content-type":"Application/json"},"JSON":{"name":"Zhangsan","Password":"123456"} 2, headers for application/x-www-form-urlencoded type, followed by a forms"Headers":{"Content-type":"application/x-www-form-urlencoded"},"Forms":{"name":"Zhangsan","Password":"123456"} 3, request requests have 14 fixed properties: Method,headers,json,factory,uri,text,cookies,xpaths, Json_paths,version,file,queries, Path_resource,forms. Be sure to follow these methods. Common method (Request mode), headers (heads parameter), URI (URL address), file (request file specified), queries (request with parameter), Forms (Form content). 4, the response response has 12 fixed properties: Status,attachment,headers,version,factory,file,text,proxy,cookies,json,latency,path_ Resource 5, Delay"Response":{"Latency":{"Duration":1,"Unit":"Second"},"file":"Login/login_fail_response.json"}

Detailed demo address: GitHub Reference Documentation: mac Simple Implementation server build (local) and iOS debugging Zero Foundation of Dry Goods series build self-test server

Moco Server jar package for easy API Setup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.