Filter using FrontQL
Introduction
In web applications, filtering data based on specific values is a common requirement. FrontQL allows you to filter data using the filter
query parameter.
Implementing Filter
- Use the
filter
query parameter to specify the criteria. - If filter changes, the token has to be regenerated.
- It is passed to the headers of the request.
Example
Here’s a simple example of implementing filter using FrontQL:
async function getUsers() { const response = await Api.get("/users", { filter: "name:John", });
return response;}
async function getUsers() { const url = `${BASE_URL}/users`; // Replace BASE_URL with the base URL of API server const response = await fetch(url, { method: "GET", headers: { "Content-Type": "application/json", filter: "name:John", app: DATABASE, // Replace DATABASE with the name of your database token: TOKEN, // Replace TOKEN with the token // OR // Authorization: `Bearer ${AUTH_TOKEN}`, // Replace AUTH_TOKEN with the authorization token, } })
const data = await response.json(); return data;}
In this example, the
filter
query parameter is used to specify that theusers
collection should be filtered by thename
field. The filter is done on thename
field in theusers
collection.