mountebank icon indicating copy to clipboard operation
mountebank copied to clipboard

Feature Request: fromDataSource.json

Open ericmacfarland opened this issue 5 years ago • 0 comments

It would be fantastic if we could perform data look-ups on JSON, instead of only on CSV files!

For example, suppose I have two routes:

  • /comments -- Returns a list of all comments, where each comment has an id
  • /comments/:id -- Returns the comment that has the specified id

Given the below source data:

[
    {
        "id": 1,
        "name": "id labore ex et quam laborum",
        "body": "laudantium enim quasi est quidem magnam"
    },
    {
        "id": 2,
        "name": "quo vero reiciendis velit similique earum",
        "body": "est natus enim nihil est dolore omnis"
    },
    {
        "id": 3,
        "name": "odio adipisci rerum aut animi",
        "body": "quia molestiae reprehenderit quasi"
    },
    {
        "id": 4,
        "name": "alias odio sit",
        "body": "non et atque\noccaecati deserunt"
    }
]

We can already send the whole list back for the /comments route, but sending back a specific item from that list (based on input) is either fair bit more challenging, or quite verbose.

Currently, there appear to be two viable approached:

  1. Generate a CSV file where the row number corresponds to the ID, and then use the built-in CSV lookup functionality. This leads to data duplication, and requires regeneration when the source changes.
  2. Dynamically generate stubs for /comments/1, /comments/2, and so on. This leads to a large number of stubs as the size of the data increases.

ericmacfarland avatar Dec 06 '19 18:12 ericmacfarland