This topic discusses the custom data provider specification.
Registration Object
Every custom data provider has a file named index.js that exports a registration object containing provider information. The object describes how to load and use the provider. The following is the code that is automatically included in the index.js file by the Custom Data Feeds (CDF) command line tool.
const packageInfo = require('../package.json');
const csconfigInfo = require('../cdconfig.json');
const provider = {
type: csconfigInfo.type,
name: csconfigInfo.name,
version: packageInfo.version,
Model: require('./model')
};
module.exports = provider;The table below describes each field in detail:
| Name | Required | Type | Description |
|---|---|---|---|
type | string | Set to 'provider' | |
name | string | URL-safe provider name | |
version | string | Provider version number | |
Model | class | require statement for Model class | |
routes | Object[] | Array of provider-specific route objects | |
Controller | class | Controller class that supports route handling |
The auto-generated code pulls the provider version from the package.json file and other fields from the cdconfig.json file. To modify these fields, change the corresponding values in the cdconfig.json file instead of the index.js file. In general, developers should have no need to edit this file. The explanation here is only for reference.
Model Class
Every custom data provider implements a Model class, which is usually
in the model.js file. The Model class includes a required get method
that will contain code for fetching and tranforming remote data into GeoJSON. It may optionally include the
edit method for handling feature editing, the authorize() method for handling custom user authorization, or the get method.
The following table describes the arguments that the get method accepts. The callback is
optional because the get method may be an async function if desired.
| Name | Description |
|---|---|
| Type: Example |
| Type: Example |
Request Object
The following table shows the properties that are availble on the request object. The example column is not exhaustive.
| Name | Description |
|---|---|
| The Example |
| The Example |
| The Example |
GeoJSON Metadata Fields
Custom Data Feeds requires that the GeoJSON be decorated with a property called metadata.
It should have an object as its value. This object contains information important for
translating the GeoJSON to its feature service equivalent. The table below describes
some of the key metadata properties:
| Field | Details |
|---|---|
| Type: |
| Type: |
| Type: |
| Type: Example Refer to this table for the possible See the ArcGIS REST Documentation for other details on data types such as coded value and range |
| Type: |
| Type: |
| Type: |
| Type: |
| Type: |
| Type: Example See the ArcGIS REST Documentation for more details on labeling options. |
| Type: |
| Type: |
| Type: |
| Type: |
| Type: |
| Type: Example |
If your data does not contain a field that can be used as the OBJECTID, you can leave id undefined.
In such cases Custom Data Feeds will create an OBJECTID for each feature by default. However, this is
less than ideal as it impacts performance and in very rare cases may lead to OBJECTID collisions. The
best practice is to have a field on the raw data that meets the requirements of id. See Setting
the idField Property for more details.
More GeoJSON Properties
The properties listed in the table below are not part of the metadata object. They are properties to be attached to the returned geoJSON object.
async getData(req) {
// rest of code
return
{
...geojson, // using spread operator to append filtersApplied and metadata to geojson
filterApplied,
metadata
}
}| Field | Details |
|---|---|
| Type: |
Routes and Controllers
Routes
To use provider-specific routes, ensure that the routes field in the
index.js file points to a file that exports an array of route
definition objects. The following table describes the fields that each
route definition object must contain.
| Name | Description |
|---|---|
| Type: |
| Type: |
| Type: |
Controllers
Set the handler field of each route definition object to the function
name that handles requests for that route. You can define these
functions in a Controller class. The Controller field in the
index.js file must reference the Controller class. Below is an
example of how to implement a Controller class.
function Controller (model) {
this.model = model;
}
Controller.prototype.test = function (req, res) {
res.status(200).json({version: '1.0.0'});
};