Skip to content

How can extensions contribute Entities with persistence behavior and REST API #5476

@bajtos

Description

@bajtos

This story is extracted from #4099, where we researched existing LoopBack 3 components and various techniques they use.

Now we need to write documentation for extension authors to show how to solve the following use cases in LoopBack 4:

  • Contribute custom entities (Application, Installation) to be persisted via CRUD, exposed via REST and possibly further customized by the app. Customization options include which datasource to use, the base path where REST API is exposed (e.g. /api/apps and /api/devices), additional fields (e.g. Application.tenantId) and changes in persistence behavior (e.g. via Operation Hooks)

  • Add a custom Operation Hook to given models, with a config option to enable/disable this feature. The list of models can be provided explicitly in the component configuration or obtained dynamically via introspection (e.g. all models having a "belongsTo" relation with the Group model). This may require How can extensions introspect application artifacts #5426 How can extensions introspect application artifacts.

  • Add new relations, e.g. between an app-provided entity User and a component-provided entity File. In this variant, the relation is added on small fixed number of models.

  • A model mixing adding new relations (hasMany ModelEvents), installing Operation Hooks (to generate model events/audit log entries), adding new Repository APIs (for working with related model events).

    (The mixin-based design may be difficult to accomplish in LB4, we may want to use introspection and a model setting instead. The trickier part is how to apply changes to models added after the component was mounted.)

  • For all models with a flag enabled in model settings, setup a custom afterRemote hook to modify the HTTP response (e.g. add additional headers).

In most cases, the new content will be useful to authors building new LB4 components too, therefore we should structure the content in two parts:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions