You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'd like to add some additional backend logic that happens whenever a POST /api/myEntity or another operation on that entity is requested. It should be able to receive the body data and do some processing, likely asynchronously, while Remult persists the entity to the database.
Describe the solution you'd like
One option is like the Live Queries/subscriptions feature, where I register a myEntityRepo.subscribe(({items, applyChanges, changes}) => { // my logic }) handler. Likely using the changes field I can handle different events corresponding to various HTTP verbs.
Another option would be "hooks" for the regular CRUD API routes, like:
@BackendMethod({hook: true})staticasyncinsert(entity: Entity){constentityRepo=remult.repo(Entity)awaitPromise.all([entityRepo.save(entity),async()=>{kafka.send({entity})}])// or justawaitPromise.all([entityRepo.insert(entity),async()=>{kafka.send({entity})}])}// orstaticasyncbeforeInsert(entity: Entity){entity.name=entity.name.toUpperCase();returnentity}
Describe alternatives you've considered
I looked at BackendMethods, but AFAICT I'd need to add duplicate API routes for every action I wanted to override, breaking the uniform HTTP and remult frontend library interfaces. I'd like to be able to override those routes to perform slightly different logic but still have the easy default action as an ideally one-line function call.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I'd like to add some additional backend logic that happens whenever a
POST /api/myEntity
or another operation on that entity is requested. It should be able to receive the body data and do some processing, likely asynchronously, while Remult persists the entity to the database.Describe the solution you'd like
One option is like the Live Queries/subscriptions feature, where I register a
myEntityRepo.subscribe(({items, applyChanges, changes}) => { // my logic })
handler. Likely using thechanges
field I can handle different events corresponding to various HTTP verbs.Another option would be "hooks" for the regular CRUD API routes, like:
Describe alternatives you've considered
I looked at
BackendMethod
s, but AFAICT I'd need to add duplicate API routes for every action I wanted to override, breaking the uniform HTTP and remult frontend library interfaces. I'd like to be able to override those routes to perform slightly different logic but still have the easy default action as an ideally one-line function call.The text was updated successfully, but these errors were encountered: