> For the complete documentation index, see [llms.txt](https://docs.wirebootstrap.com/wirebootstrap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wirebootstrap.com/wirebootstrap/reference/wire.data/wire.data.datasource.md).

# wire.data.DataSource

Use the `DataSource` class to create a connection to a data service.

## Properties

| Name        | Type   | Default | Description                                                                                                                                                                                                   |
| ----------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Ajax        | object | null    | Ajax options used by the data source [service provider](/wirebootstrap/connecting-to-data/data-connectors.md) to make calls to the data service if using [jQuery Ajax](https://api.jquery.com/jquery.ajax).   |
| Headers     | object | null    | Attached headers to the data service call.  See [Authentication](#basic-authentication) for an example.                                                                                                       |
| Model       | object | null    | Optional [wire.data.DataModel](/wirebootstrap/reference/wire.data/wire.data.datamodel.md) to be used by the data source.                                                                                      |
| Provider    | object | null    | Configuration for the service provider used by the data source.  This will be specific to the service provider.  Visit [Service Providers](/wirebootstrap/connecting-to-data/data-connectors.md) for details. |
| ServiceRoot | string | null    | URL end point for the data service used by the data source.                                                                                                                                                   |

## Methods

| Name             | Description                                                                                                                                                                |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| allow            | Returned from the service provider.  See [Allow](/wirebootstrap/reference/wire.data/wire.data.datasource.md#allow) details below.                                          |
| cast             | Static method that casts an object with the same data source properties into an instance of the `DataSource` class.                                                        |
| delete           | Deletes data from a data service.  See [Writing Data Deletes](/wirebootstrap/deletes.md) for details.                                                                      |
| deleteAsync      | Deletes data from a data service.  See [Writing Data Deletes](/wirebootstrap/deletes.md) for details.                                                                      |
| exec             | Executes a query in a data service.                                                                                                                                        |
| execAsync        | Executes a query in a data service.                                                                                                                                        |
| getResponseTable | Call into the service provider to transform data returned from a data service into a [DataTable](/wirebootstrap/reference/wire.data/wire.data.datatable.md).               |
| serviceProvider  | Returns the service provider instance.  Visit [Service Providers](/wirebootstrap/connecting-to-data/data-connectors.md) for details.                                       |
| test             | Service provider must set [allow().test](/wirebootstrap/reference/wire.data/wire.data.datasource.md#allow) for consumers to be sure testing the data service is supported. |
| useBasicAuth     | Tells the service provider to use Basic authentication when calling into the data service                                                                                  |
| useBearerAuth    | Tells the service provider to use Bearer authentication when calling into the data service                                                                                 |
| write            | Use this method to update data in a data service.  See [Writing Data Updates](/wirebootstrap/untitled.md#writing-data) for details.                                        |
| writeAsync       | Use this method to update data in a data service.  See [Writing Data Updates](/wirebootstrap/untitled.md#writing-data) for details.                                        |

## Authentication

Use the `Headers` property to attach headers to the data service call.

```javascript
const token = "Ajb9fur9jgk9f6jr";

const source = new wire.data.DataSource("custom", {
    Headers: { Authorization: "Bearer " + token }
});
```

The example above uses a token with the `Bearer` authentication.  Below is an example that uses `Basic` authentication with a user name and password.

```javascript
const userName = "pdougherty";
const password = "Password21#$"

const source = new wire.data.DataSource("custom", {
    Headers: { Authorization: "Basic " + window.btoa(user + ":" + password) }
});
```

## Allow

The allow method exposes certain aspects of functionality available in the service provider.

| Name               | Type    | Default | Description                                                                                                                                                                      |
| ------------------ | ------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| discover           | boolean | false   | Does the service provider allow meta data about data elements in the data service to be dynamically read.                                                                        |
| tableQuery         | boolean | true    | Does the service provider support building queries using [TableQuery](/wirebootstrap/reference/wire.data/wire.data.tablequery.md).                                               |
| tableQuery.orderBy | number  | 0       | Does table query support include the `orderBy` function.  0 = does not support order by, 1 = order by on a single field is supported, 2 = order by supported on multiple fields. |
| tableQuery.groupBy | boolean | false   | Does the service provider support the `groupBy` function.                                                                                                                        |
| test               | boolean | false   | Does the service provider support testing data service availability.                                                                                                             |
| storedProcedure    | boolean | false   | Does the service provider support building queries using                                                                                                                         |

## Discover Methods

Use the following methods to read meta data about the data contained in a data service.

All the *discover* methods take a singe options parameter.  This parameter will be specific to the service provider if applicable at all.  See [DataSource Discovery](/wirebootstrap/connecting-to-data/discovery.md) for examples.  Visit the service provider documentation for details on discovery options.

| Name                                     | Description                                                                                                                 |
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| discoverCatalogs                         | Returns the list of catalogs or databases from a data service using a synchronous call.                                     |
| discoverCatalogsAsync                    | Returns the list of catalogs or databases from a data service using an asynchronous call.                                   |
| discoverEntities                         | Returns the list of entities or tables from the database defined in the data service connection using a synchronous call.   |
| discoverEntitiesAsync                    | Returns the list of entities or tables from the database defined in the data service connection using an asynchronous call. |
| discoverFields(config)                   | Returns the list of fields for an entity or table specified in `config.entity`using a synchronous call.                     |
| discoverFieldsAsync(config)              | Returns the list of fields for an entity or table specified in `config.entity`using an asynchronous call.                   |
| discoverProcedures                       | Returns the list of stored procedures from the database defined in the data service connection using a synchronous call.    |
| discoverProceduresAsync                  | Returns the list of stored procedures from the database defined in the data service connection using an asynchronous call.  |
| discoverProcedureParameters              | Returns the list of parameters for a stored procedure specified in `config.procedure`using a synchronous call.              |
| discoverProcedureParametersAsync(config) | Returns the list of parameters for a stored procedure specified in `config.procedure`using an asynchronous call.            |
|                                          |                                                                                                                             |

For more on data sources, visit [Connecting to Data](/wirebootstrap/connecting-to-data/data-connectors.md).
