Custom Rest Endpoint
An app behavior can be of type "Endpoint". This adds a custom REST endpoint to the application.
The Auth0 Client Configuration in the Auth0 Loopback 4 library is a good example. It adds an endpoint "/api/auth0ClientConfiguration" that is called from the client side to get the Auth0 domain and client id at runtime. This allows one app build to be used with many different Auth0 configurations.
Endpoint App Behaviors can be called from User Interface Methods using the following shortcut: Include ApexAppService in your User Interface Dependencies, then call the behavior from your method using:
// Call endpointBehaviorName Endpoint App Behavior from a User Interface Method await this.apexAppService.endpointBehaviorName();
An event handler is executed when specific events happen. The event can be a standard Loopback event or a custom event.
The Monitor Datasources behavior in the Loopback 4 Base Library is a good example of an event that happens when the app has started. It waits for the app to start and then sets an interval to check the status of the database connection pool.
The Set Up Socket Io Server behavior in the Socket Io Library is a good example of using a custom event. It waits for the "Schema Up To Date" event that is published by the Update Schema observer and then sets up the Postgres Adapter for socket.io so that realtime messaging works across nodes.
Reusable behaviors are functions that can be called in App Behaviors and Business Object Behaviors. A reusable behavior has parameters (inputs) and a return type (output type). By default, a reusable behavior is an async functions but you can change a reusable behavior to a synchronous function by clicking the settings icon button.