# SweApiFetch

SweApiFetch is a specific DataSource to parse SweApi JSON data.

The class inherits directly from TimeSeriesDataSource.

There are not specific properties for this DataSource.


API Reference

# Parser

Depending on the format, the input could be JSON, binary, xml, etc. data. Whatever the input format, the datasource will format the data in a homogeneous way to be read in the same way by Layers and Views.

The time field formatted as String ISO Date is converted into time in milliseconds.

The other fields are keeping as they are and are forwarded to the result object.

# Properties

Several properties are available:

  • responseFormat: defines the input format for the generic parser
  • protocol: ws/mqtt

Often the available formats are:

  • application/om+json
  • application/swe+json
  • application/swe+binary
  • application/swe+csv

SweApi supports MQTT protocol. A mqttOpts property is available to setup prefix and endpointUrl of the Mqtt server.

The general endpointUrl is still use for fetching resources only.

The prefix is a collection route prefix such as:

  • prefix='/api'
  • resource='/datastreams/gal7w6j6v7n9/observations'

Result = /api/datastreams/gal7w6j6v7n9/observations

# Examples: responseFormat=application/om+json format

From Server:

{
  "datastream@id": "gal7w6j6v7n9",
  "foi@id": "xcz0cdcxyy5y",
  "phenomenonTime": "2012-06-29T14:33:57.533Z",
  "resultTime": "2012-06-29T14:33:57.533Z",
  "result": {
    "location": {
      "lat": 34.7018644887497,
      "lon": -86.65802913096641,
      "alt": 3047.812619211108
    }
  },
  "timestamp": 1340980437533
}

After parsing:

{
  "dataSourceId": "DataSource-a6472266-f869-5b0d-8632-3aa0c24569b1",
  "type": "data",
  "values": [
    {
      "data": {
        "timestamp": 1340980437533,
        "location": {
          "lat": 34.7018644887497,
          "lon": -86.65802913096641,
          "alt": 3047.812619211108
        }
      },
      "version": -9007199254740991
    }
  ]
}

# Example

import SweApiFetch from "osh-js/core/datasource/sweapi/SweApi.datasource.js";
import {Mode} from "osh-js/core/datasource/Mode";

let gpsDataSource = new SweApiFetch("android-GPS", {
  endpointUrl: 'api.georobotix.io/ogc/t18/api',
  resource: '/datastreams/o7pce3e60s0ie/observations',
  tls: true,
  protocol: 'mqtt',
  mqttOpts: {
    prefix: '/api',
    endpointUrl: 'api.georobotix.io:443/ogc/t18'
  },
  mode : Mode.REAL_TIME
});