dreamhead / moco

Easy Setup Stub Server
MIT License
4.36k stars 1.08k forks source link

Does MOCO support global variable with random value in a json file? #239

Open yqleng1987 opened 6 years ago

yqleng1987 commented 6 years ago

I want to define a global variable which could be used anywhere (request/response/event/...) in the json file and its value is random.

yqleng1987 commented 6 years ago

Is that possible to add a new part to define global variables in a json file? For example:

[
  {
    "variables" : 
    {
        "v1" : "Mike",
        "v2" : RANDOM
    },
    "request" :
    {
      "method" : "get",
      "uri" : "/test"
    },
    "response" :
    {
      "text" : "${v1}"
    },
    "on" :
    {
      "complete" :
      {
        "async" : "true",
        "latency" : 1000,
        "post" :
        {
          "url" : "http://another_site",
          "content" : "${v2}"
        }
      }
    }
  }
]
dreamhead commented 6 years ago

I'm working on random template function.

You suggestion is really good. I'll try to figure out a solution to separate variables.

valens77 commented 4 years ago

Is this problem solved now?