UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

98 lines (52 loc) 1.99 kB
--- lang: en title: 'API docs: context.context.get' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context permalink: /doc/en/lb4/apidocs.context.context.get.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [Context](./context.context.md) &gt; [get](./context.context.get.md) ## Context.get() method Get the value bound to the given key, throw an error when no value is bound for the given key. **Signature:** ```typescript get<ValueType>(keyWithPath: BindingAddress<ValueType>, session?: ResolutionSession): Promise<ValueType>; ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> keyWithPath </td><td markdown="1"> [BindingAddress](./context.bindingaddress.md)<!-- -->&lt;ValueType&gt; </td><td markdown="1"> The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve. </td></tr> <tr><td markdown="1"> session </td><td markdown="1"> [ResolutionSession](./context.resolutionsession.md) </td><td markdown="1"> _(Optional)_ Optional session for resolution (accepted for backward compatibility) </td></tr> </tbody></table> **Returns:** Promise&lt;ValueType&gt; A promise of the bound value. ## Example ```ts // get the value bound to "application.instance" const app = await ctx.get<Application>('application.instance'); // get "rest" property from the value bound to "config" const config = await ctx.get<RestComponentConfig>('config#rest'); // get "a" property of "numbers" property from the value bound to "data" ctx.bind('data').to({numbers: {a: 1, b: 2}, port: 3000}); const a = await ctx.get<number>('data#numbers.a'); ```