# API handlers for saving and loading

## Overview

You can use the API handlers instead of the [predefined REST API] to store:

- [chart layouts]
- [chart templates]
- [indicator templates]
- [drawing templates]

When users click the save or load buttons in the UI, these actions initiate the saving and loading processes.
API handlers allow implementing custom logic for save/load actions coming from UI.
For example, you can add authorization headers or manage specific errors.
Note that you need to have your own backend service to use API handlers.

## How to implement

Add the [`save_load_adapter`] property to the [Widget Constructor].
`save_load_adapter` is an [`​IExternalSaveLoadAdapter`] object that contains the save/load functions.
The library calls these functions when users click save/load UI elements.

## Examples

### localStorage

The TypeScript example below shows how to implement in-memory saving logic, so that the data is saved within the browser's [localStorage].

See the Pen 
  Saving chart content to browser's localStorage using save_load_adapter by TradingView (@tradingview)
  on CodePen.

### In-memory

The JavaScript example below shows how to implement in-memory saving logic, so that the data is saved only within the memory of the current tab.
You can use this example for testing purposes or improve it by replacing the internals of these methods with calls to an external server.

See the Pen 
  Saving templates to in-memory storage using save_load_adapter by TradingView (@tradingview)
  on CodePen.

[chart layouts]: https://charting-library-docs.xstaging.tv/latest/saving_loading.md#chart-layouts
[chart templates]: https://charting-library-docs.xstaging.tv/latest/saving_loading.md#chart-templates
[drawing templates]: https://charting-library-docs.xstaging.tv/latest/saving_loading.md#drawing-templates
[`​IExternalSaveLoadAdapter`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.IExternalSaveLoadAdapter
[indicator templates]: https://charting-library-docs.xstaging.tv/latest/saving_loading.md#indicator-templates
[localStorage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
[predefined REST API]: https://charting-library-docs.xstaging.tv/latest/saving_loading/save-load-rest-api.md
[`save_load_adapter`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ChartingLibraryWidgetOptions#save_load_adapter
[Widget Constructor]: https://charting-library-docs.xstaging.tv/latest/configuration/Widget-Constructor.md

---

## Sitemap

- [All documentation pages](https://charting-library-docs.xstaging.tv/llms.txt)
- [Full page map with headings](https://charting-library-docs.xstaging.tv/docs_map.md)
