# Facade API

> Learn how to add Facade API to your application to simplify the usage of Web SDK.

- Human documentation: [https://docs.univer.ai/guides/docs/getting-started/facade](https://docs.univer.ai/guides/docs/getting-started/facade)

- Agent Markdown: [https://docs.univer.ai/guides/docs/getting-started/facade.md](https://docs.univer.ai/guides/docs/getting-started/facade.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [docs/getting-started/facade.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/getting-started/facade.mdx)

---

In order to meet complex requirements, Univer's architecture is also quite complex, which may cause some difficulties in usage. To address this, we provide a simpler and more user-friendly Facade API.

This chapter will show in detail how to add Facade API to your application. In the following “Features” chapter, we will list the main Facade API of each feature. If you want to see all the Facade API, please refer to the API reference of each plugin.

> [!WARNING: Cuation]
> Some Facade APIs are asynchronous, especially those that modify data, which often return a Promise. If you need to retrieve data immediately after modifying it, please use `await` or `.then()`, otherwise, you may get unexpected results. To find out which specific APIs return Promises, please refer to the corresponding API reference manual.

## Integrating Facade API in Preset Mode

If you integrate Univer with preset mode, it will automatically import the Facade API for the included features and return a corresponding Facade API instance `univerAPI` when you create a Univer instance. You can use it directly.

## Integrating Facade API in Plugin Mode

### Installation

To integrate Facade API in the case of installing Univer through plugin mode, the implementation of Facade API is distributed across various plugins and mounted on the global Facade API root object. This means that for those plugins that provide Facade API, you can import their corresponding Facade API implementations as needed.

```typescript
import { FUniver } from '@univerjs/core/facade'

import '@univerjs/ui/facade'
import '@univerjs/docs/facade'
import '@univerjs/docs-ui/facade'
```

> [!WARNING: Cuation]
> Not all plugins include a facade package; we will specify this in the documentation for each feature.

### Usage

```typescript
import { FUniver } from '@univerjs/core/facade'

const univerAPI = FUniver.newAPI(univer)
```

### Cautions

Not all Facade APIs can be called immediately; some APIs need to be used at specific lifecycle stages. If you encounter issues with immediate execution, please refer to the following method to choose the appropriate lifecycle stage for execution:

```typescript
const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {
  if (stage === univerAPI.Enum.LifecycleStages.Rendered) {
    // Code to be executed when the lifecycle stage is Rendered
  }
  if (stage === univerAPI.Enum.LifecycleStages.Steady) {
    // Code to be executed when the lifecycle stage is Steady
  }
})
```
