You can use List Express API to link the client UI(especially editors like Select or SuggestBox with remote data source) and sever data model.
List Express API helps to perform the next requests:
Method | URL | Description |
---|---|---|
GET | / | Get all records |
GET | /label/:recordId | Get particular record label |
const listApiBuilder = UIKernel.listExpressApi(); //initializes builder
listApiBuilder.model(listModel);
listApiBuilder.model(getModel);
Specify a list model which must implement List Model Interface and can be an instance or a constructor so that the List Express Api will be able to use the provided data model to perform client requests.
Parameters:
Type | Name | Description |
---|---|---|
FormModel | listModel | Required. The instance of a List model |
Or:
Type | Name | Description |
---|---|---|
Function | getModel | Required. Function to be called with Express middleware’s req and res parameters returning a List model instance |
listApiBuilder.result(callback);
Specify a function to be called when the response is ready.
Parameters:
Type | Name | Description |
---|---|---|
Function | callback | Optional. Function to be called with the result. |
callback
s arguments:
Type | Name | Description |
---|---|---|
Any | err | Error caught from model methods |
Any | data | Result returned by model methods |
const router = listApiBuilder.getRouter();
Creates an Express router object with middlewares performing requests specified above.
Pass a model instance to Express API:
import citiesListModel from 'somewhere';
const router = UIKernel.listExpressApi()
.model(citiesListModel)
.getRouter();
Or use a constructor for that:
import CitiesListModel from 'somewhere';
const router = UIKernel.listExpressApi()
.model((req, res) => {
return new CitiesListModel(req.params.countryId);
})
.getRouter();
You can also customize your API by adding other methods or define API using other frameworks.
To interact with this API at front-end use List XHR Model.
import model from 'somewhere';
const router = UIKernel.gridExpressApi()
.model(model)
.getRouter()
//here you can add performing of some other API requests:
.put('/:recordId', function (req, res, next) {
model.updateRecord(req.params.recordId)
.then(function () {
res.sendStatus(200);
})
.catch(function (err) {
next(err);
})
});