Skip to content

A Javascript SDK for NGSI v2. It allows to quickly develop applications interacting with NGSI v2 API.

License

Notifications You must be signed in to change notification settings

smartsdk/ngsi-sdk-javascript

Repository files navigation

NGSI v2 Javascript and NodeJS SDK

This SDK is automatically generated by the Swagger Codegen project:

  • API version: v2 RC-2018.04 (available here)
  • Package version: 0.2.0
  • Build package: io.swagger.codegen.languages.JavascriptClientCodegen

Installation

npm

The library is available at npmjs.

To install it via npmjs:

npm install ngsi_v2 --save
Local development

To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json (and this README). Let's call this JAVASCRIPT_CLIENT_DIR. Then run:

npm install

Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR:

npm link

Finally, switch to the directory you want to use your ngsi_v2 from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('ngsi_v2') in javascript files from the directory you ran the last command above from.

git

If you fork and customise the library, in a git repository, e.g. https://github.com/smartsdk/ngsi-sdk-javascript.git then install it via:

    npm install https://github.com/smartsdk/ngsi-sdk-javascript.git --save

For browser

The library also works in the browser environment via npm and browserify. The latest compiled version of the javascript library is available at https://smartsdk.github.io/ngsi-sdk-javascript/js/ngsi.js

To embed it in your HTML code:

<script src="https://smartsdk.github.io/ngsi-sdk-javascript/js/ngsi.js"></script>

In case of changes to the code, after following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following:

browserify js/main.js --require superagent --exports require -o js/ngsi.js

Then include ngsi.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Getting Started

Please follow the installation instruction and execute the following JS code:

var NgsiV2 = require('ngsi_v2');

var defaultClient = NgsiV2.ApiClient.instance;

// Configure API key authorization: fiware_token
var fiware_token = defaultClient.authentications['fiware_token'];
fiware_token.apiKey = "YOUR API KEY"
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//fiware_token.apiKeyPrefix['X-Auth-Token'] = "Token"

var api = new NgsiV2.APIEntryPointApi()

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
api.retrieveAPIResources(callback);

Documentation for API Endpoints

All URIs are relative to http://orion.lab.fiware.org:1026/v2

Class Method HTTP request Description
NgsiV2.APIEntryPointApi retrieveAPIResources GET /
NgsiV2.AttributeValueApi getAttributeValue GET /entities/{entityId}/attrs/{attrName}/value
NgsiV2.AttributeValueApi updateAttributeValue PUT /entities/{entityId}/attrs/{attrName}/value
NgsiV2.AttributesApi getAttributeData GET /entities/{entityId}/attrs/{attrName}
NgsiV2.AttributesApi removeASingleAttribute DELETE /entities/{entityId}/attrs/{attrName}
NgsiV2.AttributesApi updateAttributeData PUT /entities/{entityId}/attrs/{attrName}
NgsiV2.BatchOperationsApi notify POST /op/notify
NgsiV2.BatchOperationsApi query POST /op/query
NgsiV2.BatchOperationsApi update POST /op/update
NgsiV2.EntitiesApi createEntity POST /entities
NgsiV2.EntitiesApi listEntities GET /entities
NgsiV2.EntitiesApi removeEntity DELETE /entities/{entityId}
NgsiV2.EntitiesApi replaceAllEntityAttributes PUT /entities/{entityId}/attrs
NgsiV2.EntitiesApi retrieveEntity GET /entities/{entityId}
NgsiV2.EntitiesApi retrieveEntityAttributes GET /entities/{entityId}/attrs
NgsiV2.EntitiesApi updateExistingEntityAttributes PATCH /entities/{entityId}/attrs
NgsiV2.EntitiesApi updateOrAppendEntityAttributes POST /entities/{entityId}/attrs
NgsiV2.RegistrationsApi createRegistrations POST /registrations
NgsiV2.RegistrationsApi deleteRegistration DELETE /registrations/{registrationId}
NgsiV2.RegistrationsApi retrieveRegistration GET /registrations/{registrationId}
NgsiV2.RegistrationsApi retrieveRegistrations GET /registrations
NgsiV2.RegistrationsApi updateRegistration PATCH /registrations/{registrationId}
NgsiV2.SubscriptionsApi createANewSubscription POST /subscriptions
NgsiV2.SubscriptionsApi deleteSubscription DELETE /subscriptions/{subscriptionId}
NgsiV2.SubscriptionsApi retrieveSubscription GET /subscriptions/{subscriptionId}
NgsiV2.SubscriptionsApi retrieveSubscriptions GET /subscriptions
NgsiV2.SubscriptionsApi updateSubscription PATCH /subscriptions/{subscriptionId}
NgsiV2.TypesApi retrieveEntityType GET /types/{entityType}
NgsiV2.TypesApi retrieveEntityTypes GET /types/

Documentation for Models

Documentation for Authorization

fiware_token

  • Type: API key
  • API key parameter name: X-Auth-Token
  • Location: HTTP header

About

A Javascript SDK for NGSI v2. It allows to quickly develop applications interacting with NGSI v2 API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published