# Named Sources

With **Named Sources** you can make sure that your applications **communicate with CARTO** **without exposing SQL queries** in the code or through the network requests.

Using Named Sources in your application does not change the overall architecture, which will remain very efficient, lightweight and modern — in most cases, it won't require additional backend services.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-e4ff397a7967f6e7a579d2e3a4158d54a3afcc92%2FScreenshot%202024-11-22%20at%2009.43.57.png?alt=media" alt=""><figcaption></figcaption></figure>

## How does a Named Source work

Named Sources work by using a very simple principle:

1. Store a SQL query in CARTO as a Named Source.
2. Use your new Named Source in a [CARTO for Developers](https://github.com/CartoDB/gitbook-documentation/blob/master/carto-user-manual/developers/broken-reference/README.md) application by simply referencing its name instead of a SQL Query, in any function or endpoint that accepts a `sqlQuery` parameter.

```typescript
const data = vectorQuerySource({
  ...config,
  sqlQuery: 'named_source_1', // your named source
});

```

## Creating a Named Source

To create a new Named Source, go to Developers > Named Sources and click on "Create New". For each Named Source, you'll need to define:

* **Name:** this will be the reference you will be using in your application's code.
* **SQL statement:** the SQL query that will be used when this Named Source is referenced. Please note that all SQL functionalities are supported, including query parameters.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-73679c0d4c1b92e6b8e95258776cdb1ce6db380b%2FScreenshot%202024-11-22%20at%2009.45.16.png?alt=media" alt=""><figcaption></figcaption></figure>

Click on "Save Changes" and your Named Source will be ready to be used.

{% hint style="success" %}
When using [API Access Tokens](https://docs.carto.com/carto-user-manual/developers/managing-credentials/api-access-tokens), remember to add the Named Sources to the grant of the token. Otherwise, the token won't be authorized to use your Named Source.
{% endhint %}

## Managing Named Sources

Named Sources can be edited or deleted at any time. To manage them, simply click the three-dot menu next to each Named Source.

<figure><img src="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2Fgit-blob-fe537f73d13d2d35d692f7224b00952b2e84d927%2FScreenshot%202024-11-22%20at%2009.48.31.png?alt=media" alt=""><figcaption></figcaption></figure>

## Named Sources API

You can programmatically manage and deploy Named Sources using the **Named Sources API**. You can also programmatically assign Named Sources to the grants in API Access Tokens using the **Tokens API**. For more information, check the CARTO [API Reference](https://api-docs.carto.com).
