You need to create all the endpoints for the grids and forms. They have always about the same structure:
1. Get all the arguments of the request:
...\customers?key=ABC&headers=1&labels=0
These arguments defines what you need to send back in the response.
key=ABC: all the customers with ABC.
headers=1: send the header information for a grid.
labels=0: no need to send label information.
...\customers\123?labels=1
In this sample the customer with ID 123 is asked.
The labels of all the elements of the form must be send.
...\customers\grid
Returns only the headers to start a new empty grid.
2. Which command is used?
-
GET: you need to return data.
-
POST: the body in the request contains data you need to add.
-
PUT: the body in the request is an update. This can be one or multiple rows. This means there will be some reference to the original row.
-
DELETE: In the request there will be an ID so you know what to delete.
3. Open the files or connect to the database.
According to the requested endpoint, you can open the files you need.
4. Decide what to return.
In the response there will be a body with the requested data in a json format.
5. Data processing.
If you need to return data, select the data according to the key that was send.
6. Build your json response.
-
File: Start the JSON with the name of the file or table
{
"file": "countrycodes",
...
-
Headers: Create the header array to return. See
Start a grid for the structure of the headers.
"headers": [
{
"title": "Country code:",
"data": "code",
"width": "15%",
"type": "text",
"total": "",
"edit": false
}, ..... ]
-
Labels: Create the labels array to return. See
Form Elements for all the possible labels.
"labels": [
{
"display": "",
"fieldname": "id",
"length": 8,
"inputtype": "hidden",
"block": 1
},
{
"display": "Code:",
"tooltip": "",
"fieldname": "persoon",
"length": 2,
"inputtype": "text",
"block": 1,
"newline": true,
"labelwidth": 2,
"fieldwidth": 2,
"fieldheight": 1
}, ..... ]
-
Data: Create an array with the data. This can be one or multiple rows, according to the request.
"data": [
{
"id": "5",
"persoon": "BB",
"naam": "Bart"
},
{
"id": "4",
"persoon": "BO",
"naam": "Bo"
},
{
"id": "11",
"persoon": "FA",
"naam": "Fran"
},…
]
7. Close your files.
This will be dependant of your iAPI you build. In your back-end it is up to you to decide if you want to open and close your files with every request. When using SQL you can connect and disconnect each time to the database.
8. Return the response.
Returns the JSON in the body of the response. You can inflate the result to save bandwidth. It is also up to you to decide this. Personally I inflate if my json is more than 10.000 bytes. Inflating and deflating also costs time. If you have a small response you will loose time and therefore it can be better to send it as text.
9. Optimizing in speed and bandwidth.
BOA will only ask for the headers and labels if they are needed. If BOA already has the structure for the grid or form, it won't ask for it. In that case your response contains only the file and data section as below when one row is asked.
{
"file": "members",
"data": [
{
"id": "5",
"persoon": "BB",
"naam": "Bart"
}]}
10. Building JSON.
According to the tools you use, building the JSON arrays for the headers and labels can take some time. Since json is a text-string, you could easily create files that you can read and add to the response. Suppose you have an endpoint customers, you could create customers.headers.txt and customers.labels.txt as files. This way you can easily modify the content with a text editor. At the time of execution you can read the content if needed, and add it to your json response. This is some data-driven approach which will make it rather easy to change the layout and content of a grid and form. You could do the same for the data, by defining the fields in a file as customers.data.txt, processing this to create the data array can be easy.