mountebank
mountebank copied to clipboard
Feature Request: fromDataSource.json
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 anid
-
/comments/:id
-- Returns the comment that has the specifiedid
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:
- 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.
- 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.