---
lang: en
title: 'API docs: context.context.getbinding_1'
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.getbinding_1.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; [getBinding](./context.context.getbinding_1.md)

## Context.getBinding() method

Look up a binding by key in the context and its ancestors. If no matching binding is found and `options.optional` is not set to true, an error will be thrown.

**Signature:**

```typescript
getBinding<ValueType>(key: BindingAddress<ValueType>, options?: {
        optional?: boolean;
    }): Binding<ValueType> | undefined;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

key


</td><td>

[BindingAddress](./context.bindingaddress.md)<!-- -->&lt;ValueType&gt;


</td><td>

Binding key


</td></tr>
<tr><td>

options


</td><td>

{ optional?: boolean; }


</td><td>

_(Optional)_ Options to control if the binding is optional. If `options.optional` is set to true, the method will return `undefined` instead of throwing an error if the binding key is not found.


</td></tr>
</tbody></table>
**Returns:**

[Binding](./context.binding.md)<!-- -->&lt;ValueType&gt; \| undefined


