Join using FrontQL
Introduction
In web applications, it is common to join data from multiple collections. FrontQL provides the ability to join data using the join query parameter.
Implementing Join
- The
joinquery parameter is used to specify the collection(s) to join.
Example
Here’s a simple example of implementing join using FrontQL:
async function getUsers() { const response = await Api.get("/users", { join: "posts:post", });
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", collections: "posts:post", 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
joinquery parameter is used to specify that theuserscollection should be joined with thepostscollection. The join is done on thepostfield in theuserscollection, which corresponds to theidfield in thepostscollection.