WireBootstrap
HomeDocsBuySupport
  • Introduction
  • Overview
  • Getting Started
  • Installation
  • Connecting to Data
    • Data Connectors
      • SQL Data
      • Custom Web Services
      • Local Data
      • Other Sources
    • Data Sources
    • Discovery
    • Building a Data Connector
  • Working With Queries
    • Select Queries
      • Query Extensions
    • Stored Procedures
    • Custom Web Services
    • Executing Queries
    • ORM
  • Writing Data
  • Updates
  • Deletes
  • Working with DataTables
    • Introduction
    • Filter and Sort
    • Select and Calculate
    • Joins
    • Rows
    • Columns
  • Working with DataSets
  • Introduction
  • Executing Queries
  • Transforms
  • Writing Data
  • Data Events
  • Working with Components
    • Introduction
    • Encapsulation
    • Configuration
      • Data
      • Events
      • Observables
      • Validation
      • Display
      • Vendor
      • Custom
    • Component
    • Web Frameworks
    • Building a Component
      • Hello World
      • Data Events
      • DataSets
  • Working With Data Events
    • Introduction
    • Event Basics
    • Event Data
    • Event Actions
  • Working with Themes
    • Introduction
    • Sample Data
    • Libraries
    • Pages
    • Building a Theme Project
  • Utilities
    • Formatting
    • Expressions
    • Collections
    • Spinners
    • Copy and Merge
    • Validation
    • Loading Assets
    • Service Calls
    • Download Files
    • Browser Location
    • Types
    • Promise
  • Reference
    • wire
      • wire.Collection
      • wire.download
      • wire.validate
    • wire.data
      • wire.data.DataEvent
      • wire.data.DataModel
      • wire.data.DataPromise
      • wire.data.DataSet
      • wire.data.DataSource
      • wire.data.DataTable
        • Columns
        • Rows
      • wire.data.StoredProcedure
      • wire.data.TableQuery
    • wire.ui
      • wire.ui.Component
      • wire.ui.validate
Powered by GitBook
On this page
  • Create the Provider
  • Provider Configuration
  • Register the Provider
  • Allow
  • Execute Queries
  • DataTable Transform
  • Putting It All Together

Was this helpful?

  1. Connecting to Data

Building a Data Connector

PreviousDiscoveryNextSelect Queries

Last updated 3 years ago

Was this helpful?

WireBootstrap client-side Data Connectors use service providers to connect to web services.

A WireBootstrap service provider is a JavaScript function or class that implements the methods and properties expected by the data source based on the functionality of the service provider.

This section documents a sample service provider created to query the public JSON Placeholder web service at . The sample is available in a sub-project inside any edition of the download. Once downloaded, go to the\docs\building-a-data-connector directory to open the project containing the examples in this section. Double-click the index.html file to run the sample.

Create the Provider

The service provider is a simple JavaScript class or function that takes one configuration parameter. If needed, use the dataSource property on the configuration parameter to get a reference to the configuration passed into the calling data source.

const JsonPlaceHolderServiceProvider = function (config) {

  const datasource = config.dataSource;
  ...
  
}

Provider Configuration

Any service provider specific information for the data connector can be passed in using the Provider attribute when configuring the data source.

The example below passes in an API key that will be used by the service provider to authenticate calls to the web service. This key is not needed for the JSON Placeholder web service. Its used here only for demonstration.

  const source = new wire.data.DataSource("jsonplaceholder", {
    ...
    Provider: {
      apiKey: "my-test-key"
    }
  });

This configuration can then be read in and used by the service provider.

const JsonPlaceHolderServiceProvider = function (config) {

  const datasource = config.dataSource;
  const provider = datasource.Provider;
  const apiKey = provider.apiKey;  
  ...
  
}

Register the Provider

Register the service provider with the WireBootstrap framework by calling the wire.data.provider.register method.

wire.data.provider.register({
    id: "jsonplaceholder",
    provider: JsonPlaceHolderServiceProvider
});

Allow

The service provider in this example is able to transform WireBootstrap table queries into requests to the data service for data. The service provider tells the data source about this feature by setting the allow.tableQuery property to true.

...

this.allow = {
    tableQuery: true
}

Execute Queries

In the example below, the getUrl method in the project will return the transformed query as a string URL that can be used to call the web service.

The wire.get method will make an asynchronous call to the web service to retrieve the data for the query.

this.execAsync = function (query) {

    const url = getUrl(query);

    return wire.get(url);            

}

DataTable Transform

The data returned from calls to the JSON Placeholder web service is a simple array of objects so the data table is easily created by passing the data into the data table's constructor.

this.getResponseTable = function (data) {

    return new wire.data.DataTable(data);

}

Putting It All Together

Consumers can now make calls to the data service using the service provider with a data source.

The first parameter to the DataSource constructor below is the id jsonplaceholder used when the service provider was registered with WireBootstrap above. The entity on the query is todos which is filtered touserId equal to1.

const source = new wire.data.DataSource("jsonplaceholder");

const query = wire.data.select().from("todos").where().eq("userId", 1);

const result = await source.execAsync(query);

The code above will result in the following call to the web service.

GET: https://jsonplaceholder.typicode.com/todos?userId=1

For more information on data source configuration, visit .

The execAsync method on the service provider will be called by a data source to execute queries against the data service. This method takes a parameter with the inputs to the query.

After calling the asynchronous execAsync method on a service provider, the data source passes the data returned from the call to the getResponseTable method on the service provider. This method is responsible for handling any data service specific formatting and returning the data in a standard .

Visit the documentation for more details on this method.

https://jsonplaceholder.typicode.com
WireBootstrap for Gentelella
DataSource
TableQuery
DataTable
ExecAsync