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

Support querying REST API resources by query parameters #69

Closed
kettanaito opened this issue Apr 15, 2021 · 0 comments · Fixed by #70
Closed

Support querying REST API resources by query parameters #69

kettanaito opened this issue Apr 15, 2021 · 0 comments · Fixed by #70
Assignees
Labels
feature New feature or request

Comments

@kettanaito
Copy link
Member

What

Support querying REST API resources by their properties through URL query parameters.

const db = factory({
  car: {
    id: primaryKey(String),
   manufacturer: String
  }
})

setupServer(...db.car.toHandlers('rest'))

fetch('/cars?manufacturer=ford')

Where ?manufacturer=ford is transformed to a where query against the "manufacturer" property of the car:

modelApi.findMany({ where: { manufacturer: { equals: 'ford } } })

Internally, query parameters can be respected like so:

// A very, very rough code.
rest.get(..., (req, res, ctx) => {
  const parameters = serialize(req.url.searchParams)
  const result = modelApi.findMany({ where: reduceParams(parameters) })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants