Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: fromDataSource.json #488

Open
ericmacfarland opened this issue Dec 6, 2019 · 0 comments
Open

Feature Request: fromDataSource.json #488

ericmacfarland opened this issue Dec 6, 2019 · 0 comments

Comments

@ericmacfarland
Copy link

ericmacfarland commented Dec 6, 2019

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants