Skip to content

Post API

Introduction

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

The POST API of FrontQL is based on a structured query language that is both powerful and easy to understand. When a client makes a POST request to a FrontQL-enabled server, it includes a query parameter that specifies the fields and objects to be inserted. The server then processes this query and inserts the requested data.

By using the POST 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 POST API request:

async function createUser() {
const response = await Api.post("/users", {
body: {
name: "John",
},
});
return response;
}

Output

This example submits a new user to the server and returns the ID of the inserted object.

{
"err": false,
"result": {
"lastInsertID": 1,
"affectedRows": 1
}
}

Parameters

  • body : object | array

body

  • It is required for data submission.
  • It is passed to the body of the request.
  • This parameter contains the data to be inserted. The data can be a single object or an array of objects.

Multiple Inserts

  • It is possible to insert multiple objects in a single request.
  • Simply passing an array of objects to the body parameter is enough.
  • Example:
async function createUsers() {
const response = await Api.post("/users", {
body: [
{
name: "John",
},
{
name: "Jane",
},
],
});
return response;
}