Skip to content

Get API

Introduction

FrontQL is a lightweight front-end querying language designed to streamline client-server communication for web applications. It simplifies data retrieval by allowing clients to request exactly what they need from the server. One of the key features of FrontQL is its GET API, which enables clients to fetch data from the server using HTTP GET requests.

The GET API of FrontQL is based on a structured query language that is both powerful and easy to understand. When a client makes a GET request to a FrontQL-enabled server, it includes a query parameter that specifies the fields and objects to be returned. The server then processes this query and returns the requested data in a structured format, typically JSON, which can be easily consumed by the client application.

By using the GET API of FrontQL, developers can reduce the amount of data transferred over the network, minimize the need for multiple API endpoints, and ensure that applications are more performant and scalable.

Example

Here’s a simple example of a FrontQL GET API request:

async function getUsers() {
const response = await Api.get("/users");
return response;
}

Output

This example fetches all users from the server and returns them in a JSON format.

{
"err": false,
"count": 2,
"result": [
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"created_at": "2022-01-01 00:00:00.000",
"updated_at": "2022-01-01 00:00:00.000"
},
{
"id": 2,
"name": "Jane Doe",
"email": "[email protected]",
"created_at": "2022-01-01 00:00:00.000",
"updated_at": "2022-01-01 00:00:00.000"
}
]
}

Parameters

  • page : string
  • sort : string
  • joins : string
  • hidden : string
  • fields : string
  • filter : string
  • search : string

page

  • It is required for pagination.
  • There are two parameters in the page parameter: page and limit.
  • page is the page number and limit is the number of items per page.
  • page and limit are separated by a comma.
  • Example:
async function getUsers() {
const response = await Api.get("/users", {
page: "1,15", // page = 1, limit = 15
});
return response;
}

sort

  • It is required for sorting.
  • Example:
async function getUsers() {
const response = await Api.get("/users", {
sort: "-created_at",
});
return response;
}

joins

  • It is required for joining two or more collections.
  • Example:
async function getUsersPosts() {
const response = await Api.get("/posts", {
join: "user:users",
});
return response;
}

hidden

  • It is required for hiding fields which should not be returned.
  • Example:
async function getUsers() {
const response = await Api.get("/users", {
hidden: "password",
});
return response;
}

fields

  • It is required for specifying the fields to be returned.
  • Example:
async function getUsers() {
const response = await Api.get("/users", {
fields: "id,name,email",
});
return response;
}

filter

  • It is required for filtering.
  • If the filter changes, the token has to be regenerated.
  • It is passed in the headers of the request.
  • Example:
async function getUsers() {
const response = await Api.get("/users", {
filter: "name:John",
});
return response;
}
  • It is required for searching.
  • If search changes, no need to regenerate the token.
  • It is passed to the params of the request.
  • Example:
async function getUsers() {
const response = await Api.get("/users", {
search: "name:John",
});
return response;
}

Single Data Fetch

  • It is possible to fetch a single object from the server.
  • Simply add the ID of the object after the DB_NAME in the URL with a /.
  • Example:
async function getUser() {
const response = await Api.get("/users/1");
return response;
}