From the course: Building APIs with LoopBack
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Remote hooks - Node.js Tutorial
From the course: Building APIs with LoopBack
Remote hooks
- Remote hooks are a fascinating idea. They allow you to customize your API, but work with existing methods. What I mean by that is that they take an existing method and customize how it runs. It does this by letting you specify custom logic to run before or after a method. You can also define a hook to run after an error is thrown. Even cooler, you can use wildcards. So instead of saying I want to do so and so before one particular remote method is fired, I can use a wildcard to say, always run this logic before any remote method is fired. For our demo, we're going to use a remote hook to run after a cat is fetched. We're going to create a virtual property that doesn't exist on the model. That property will have a descriptive sentence about the cat. Let's look at how that's done. Alright, I'm back in my code editor, and we want to be working in the cat.js file. So if it's not open, go ahead and get it open. Alright, let's write this function. (keyboard clicking) First, I begin by…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.