entity-routes logo
Docs

Introduction#

Each entity-routes response will be formated using a template defined by the route operation , either list or details. All responses will share the @context part nonetheless. Here the actual ts type (GenericRouteResponse) :

#
ts
1type GenericRouteResponse = {
2 "@context": {
3 /** Current route operation */
4 operation: string;
5 /** Current entity's route */
6 entity: string;
7 /** Total number of items found for this request */
8 totalItems?: number;
9 /** Number of items retrieved for this request */
10 retrievedItems?: number;
11 /** Entity validation errors */
12 validationErrors?: EntityErrorResults;
13 /** Global response error */
14 error?: string;
15 };
16 /** List of entities */
17 items?: any[];
18 /** deleted entity id */
19 deleted?: any;
20 /** Entity props */
21 [k: string]: any;
22};

@context#

  • operation/entity keys are always added and define the route scope
  • On a persist operation kind, either create or update, the validationErrors key will be added and defaults to an empty array.
  • On a read operation kind, either list or details, the totalItems/retrievedItems keys will be added and defaults to empty arrays.
  • The error key is only added when there is an error, it is populated with the error message caught.

Auto reload#

You can avoid making another request on the entity details route (GET:/xxx/123) to get the latest recorded state after an entity was persisted using auto-reloading.

On persist operations (create/update), after the entity was successfully saved, it can be auto-reloaded using the shouldAutoReload key of the CreateUpdateOptions object, passed to the create/update methods of RouteController.

When an entity is auto-reloaded, it is read from the database using the getDetails method of RouteController, so that the response is returned the exact same way as if it was requested through the details route (GET:/xxx/123). The operation used is either defined explictly by using the responseOperation key of the CreateUpdateOptions object, or defaults to details elsewise.

Prev
Route Scope
Next
Formating