Default routes

Forest Admin's default routes are generated in the routes folder at installation.

Below we've detailed what the next() statement does. Those snippets can be used when overriding those routes, as explained here.

Create a record

/routes/external-companies.js
...
const {
PermissionMiddlewareCreator,
RecordCreator,
} = require('forest-express-sequelize');
const { externalCompanies } = require('../models');
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('externalCompanies');
...
// Create a External Company - Check out our documentation for more details: https://docs.forestadmin.com/documentation/v/v4/reference-guide/routes/default-routes#create-a-record
router.post('/external-companies', permissionMiddlewareCreator.create(), (request, response, next) => {
const recordCreator = new RecordCreator(externalCompanies);
recordCreator.deserialize(request.body)
.then(recordToCreate => recordCreator.create(recordToCreate))
.then(record => recordCreator.serialize(record))
.then(recordSerialized => response.send(recordSerialized))
.catch(next);
});
...

Update a record

/routes/external-companies.js
...
const {
PermissionMiddlewareCreator,
RecordUpdater,
} = require('forest-express-sequelize');
const { externalCompanies } = require('../models');
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('externalCompanies');
...
// Update a External Company - Check out our documentation for more details: https://docs.forestadmin.com/documentation/v/v4/reference-guide/routes/default-routes#update-a-record
router.put('/external-companies/:recordId', permissionMiddlewareCreator.update(), (request, response, next) => {
const recordUpdater = new RecordUpdater(externalCompanies);
recordUpdater.deserialize(request.body)
.then(recordToUpdate => recordUpdater.update(recordToUpdate, request.params.recordId))
.then(record => recordUpdater.serialize(record))
.then(recordSerialized => response.send(recordSerialized))
.catch(next);
});
...

Delete a record

...
const {
PermissionMiddlewareCreator,
RecordRemover,
} = require('forest-express-sequelize');
const { externalCompanies } = require('../models');
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('externalCompanies');
...
// Delete a External Company - Check out our documentation for more details: https://docs.forestadmin.com/documentation/v/v4/reference-guide/routes/default-routes#delete-a-record
router.delete('/external-companies/:recordId', permissionMiddlewareCreator.delete(), (request, response, next) => {
const recordRemover = new RecordRemover(actionApprovals);
recordRemover.remove(request.params.recordId)
.then(() => response.status(204).send())
.catch(next);
});
...

Get a list of records

/routes/external-companies.js
...
const {
PermissionMiddlewareCreator,
RecordsGetter,
} = require('forest-express-sequelize');
const { externalCompanies } = require('../models');
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('externalCompanies');
...
// Get a list of External Companies - Check out our documentation for more details: https://docs.forestadmin.com/documentation/v/v4/reference-guide/routes/default-routes#get-a-list-of-records
router.get('/external-companies', permissionMiddlewareCreator.list(), (request, response, next) => {
const recordsGetter = new RecordsGetter(externalCompanies);
recordsGetter.getAll(request.query)
.then(records => recordsGetter.serialize(records))
.then(recordsSerialized => response.send(recordsSerialized))
.catch(next);
});
...

Get a number of records

/routes/external-companies.js
...
const {
PermissionMiddlewareCreator,
RecordsCounter,
} = require('forest-express-sequelize');
const { externalCompanies } = require('../models');
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('externalCompanies');
...
// Get a number of External Companies - Check out our documentation for more details: https://docs.forestadmin.com/documentation/v/v4/reference-guide/routes/default-routes#get-a-number-of-records
router.get('/external-companies/count', permissionMiddlewareCreator.list(), (request, response, next) => {
const recordsCounter = new RecordsCounter(externalCompanies);
recordsCounter.count(request.query)
.then(count => response.send({ count }))
.catch(next);
});
...

Get a record

/routes/external-companies.js
...
const {
PermissionMiddlewareCreator,
RecordGetter,
} = require('forest-express-sequelize');
const { externalCompanies } = require('../models');
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('externalCompanies');
...
// Get a External Company - Check out our documentation for more details: https://docs.forestadmin.com/documentation/v/v4/reference-guide/routes/default-routes#get-a-record
router.get('/external-companies/:recordId', permissionMiddlewareCreator.details(), (request, response, next) => {
const recordGetter = new RecordGetter(externalCompanies);
recordGetter.get(request.params.recordId)
.then(record => recordGetter.serialize(record))
.then(recordSerialized => response.send(recordSerialized))
.catch(next);
});

Export a list of records

/routes/external-companies.js
...
const {
PermissionMiddlewareCreator,
RecordsExporter,
} = require('forest-express-sequelize');
const { externalCompanies } = require('../models');
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('externalCompanies');
...
// Export a list of External Companies - Check out our documentation for more details: https://docs.forestadmin.com/documentation/v/v4/reference-guide/routes/default-routes#export-a-list-of-records
router.get('/external-companies.csv', permissionMiddlewareCreator.export(), (request, response, next) => {
const recordsExporter = new RecordsExporter(externalCompanies);
recordsExporter.streamExport(response, request.query)
.catch(next);
});

Other available routes

Some other routes exist but are not generated automatically because it's less likely that you'll need to extend or override them.

Here is the list:

Relationship routes

GET /forest/{modelName}/{id}/relationships/{hasManyRelationName} ⟶ List has many relationships

GET /forest/{modelName}/{id}/relationships/{hasManyRelationName}/count ⟶ Count has many relationships

PUT /forest/{modelName}/{id}/relationships/{belongsToRelationName} ⟶ Update a belongs to field

POST /forest/{modelName}/{id}/relationships/{hasManyRelationName} ⟶ Add existing records to has many relationship

GET /forest/{modelName}/{id}/relationships/{hasManyRelationName}.csv ⟶ Download and export of an has many relationships

PUT /forest/{modelName}/{id}/relationships/{embeddedRelationName}/{index} ⟶ Update an embedded document (inside a list)

DELETE /forest/{modelName}/{id}/relationships/{hasManyRelationName} ⟶ Dissociate records from relations

Action routes

POST /forest/actions/{actionNameDasherized}/values ⟶ Get the default values for this action