iridakos / duckrails

Development tool to mock API endpoints quickly and easily (docker image available)
https://github.com/iridakos/duckrails/wiki
MIT License
1.72k stars 108 forks source link

Create mock with return alternative #47

Closed renatovieiradesouza closed 5 years ago

renatovieiradesouza commented 5 years ago

How to configure fot accept parameter empty? My ideia is return default value in case I need create a mock example: /user/v1/user-credential with params: document = 123 with return:

{
   "document" : "123"
}

But, i need create same mock name /user/v1/user-credential with return alternative, example: with params document = 092 with return

{
   "document" : "092",
   "name" : "Renato"
}

How to make this? I look the documentation, but not found solution.

iridakos commented 5 years ago

Hi @renasti You can do something like the following given you have chosen embedded ruby as the body type:

<%=
  result = { document: @parameters[:document] }

  if @parameters[:document] == '092'
    result[:name] = 'Renato'
  end

  result.to_json
%>