Originally published on strongloop.com
Hope you had a wonderful Thanksgiving for those who celebrate it! In November, LoopBack team focused on improving the context module and documentation, as well as bug fixes. The Toronto squad participated in the CASCONxEVOKE conference. Instead of a physical booth, we held a virtual one online. We welcomed @nflaig as the new maintainer of loopback-next
.
Read more to know about the highlighted improvements:
Context
A new phase
init()
was added to the application life cycle events. It is used when a component need to contribute bindings asynchronously. For example:export class MyComponent implements Component, LifeCycleObserver {
// ...
async init() {
// Contribute bindings via `init`
// This cannot be done via constructor since it's synchronous.
const val = await readFromConfig();
this.app.bind('abc').to(val);
this.status = 'initialized';
this.initialized = true;
}
}You can check the Component page to learn about its usage.
toInjectable()
was introduced as a shortcut to decorate a common/provider/dynamic-value-factory class and automatically creating binding for them. For example:@injectable({scope: BindingScope.SINGLETON})
class MyController {
constructor(@inject('my-options') private options: MyOptions) {
// ...
}
}
binding.toInjectable(MyController);The decorator's usage is well documented on page Binding.
PR #6701 updated test cases to reflect how the design types of array/undefined/complex properties are retrieved.
Method injection is allowed for the lifecycle methods in PR #6740. For example:
class MyObserverWithMethodInjection implements LifeCycleObserver {
status = 'not-initialized';
init(@inject('prefix') prefix: string) {
this.status = `${prefix}:initialized`;
}
start(@inject('prefix') prefix: string) {
this.status = `${prefix}:started`;
}
stop(@inject('prefix') prefix: string) {
this.status = `${prefix}:stopped`;
}
}In some cases, your Express middleware wants to access LoopBack's RequestContext to resolve certain bindings. This can be done via
MIDDLEWARE_CONTEXT
property of the Express request object, which is set up by LoopBack when theRequestContext
is instantiated. For example:import {MIDDLEWARE_CONTEXT, RequestContext} from '@loopback/rest';
function expressHandler(req, res, next) {
const reqCtx = (req as any)[MIDDLEWARE_CONTEXT];
// Now you have access to the LoopBack RequestContext
}
Documentation
The guide for calling REST APIs and SOAP services were separated to make the steps involved clearer. You can check the overview page Accessing services and its sub-topics Calling SOAP web services and Calling REST APIs for details.
For troubleshooting, we added steps for creating breakpoints in vscode in the documentation. You can find more details in PR #6743.
REST
- Matching a URL or hostname against a regular expression that contains an unescaped dot as part of the hostname might match more hostnames than expected. PR #6813 updated the regular expression of hostnames accordingly.
Repository
- #6755 threw 400
BadRequestError
for invalid inclusion relation name by rejecting the request with statusCode as 400.
Examples
- PR #6598 updated artifacts of the todo-list example to the latest style generated by the LoopBack CLI.
Enriching LoopBack and its Community - You are Invited!
As mentioned in our recent blog post, your contribution is important to make LoopBack a sustainable open source project.
Here is what you can do:
- Join LoopBack Slack community
- Look for first-contribution-friendly issues
- Give us feedback and join our discussion in our GitHub repo
Let's make LoopBack a better framework together!