GithubHelp home page GithubHelp logo

oxixes / ngsijs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from conwetlab/ngsijs

1.0 0.0 0.0 1.26 MB

JavaScript library for the FIWARE Context Broker services (web browsers & Node.js)

JavaScript 86.02% CSS 13.98%

ngsijs's Introduction

ngsijs

License Documentation Status Build Status Coverage Status

Ngsijs is the JavaScript library used by WireCloud for adding FIWARE NGSI capabilities to widgets and operators. However, this library has also been designed to be used in other environments as normal web pages and clients/servers running on Node.js.

This library has been developed following the FIWARE NGSI v1 and NGSI v2 specifications and has been tested to work against version 0.26.0+ of the Orion Context Broker.

Reference documentation of the API is available at http://conwetlab.github.io/ngsijs/stable/NGSI.html.

Using ngsijs from normal web pages

Note: Support for Cross-Origin Resource Sharing (CORS) has been added on orion 1.10.0. This support must be enabled to access the context broker from a web page in a different domain than the context broker.

CORS support can also be enabled by accessing to the context broker server using some proxies, like cors-anywhere or the FIWARE's pep proxy.

You can access any context broker server (without requiring CORS support and regardless of the context broker version) if the context broker is accessible throught the same domain as the web page. How to create such configuration is out of the scope of this documentation.

Just include a <script> element linking to the NGSI.min.js file:

<script type="text/javascript" src="url_to_NGSI.js"></script>

Once added the <script> element, you will be able to use all the features provided by the ngsijs library (except receiving notifications):

var connection = new NGSI.Connection("http://orion.example.com:1026");
connection.v2.listEntities().then((response) => {
    response.results.forEach((entity) => {
        console.log(entity.id);
    });
});

This example will display the id of the first 20 entities. See the documentation of the listEntities method for more info.

To be able to receive notifications inside a web browser the library requires the use of a ngsi-proxy server. You can use your own instance or the ngsi-proxy instance available at https://ngsiproxy.lab.fiware.org.

var connection = new NGSI.Connection("http://orion.example.com:1026", {
    ngsi_proxy_url: "https://ngsiproxy.lab.fiware.org"
});

Using ngsijs from Node.js

$ npm install ngsijs

After installing the ngsijs node module, you will be able to use the API as usual:

var NGSI = require('ngsijs');
var connection = new NGSI.Connection("http://orion.example.com:1026");
connection.v2.listEntities().then((response) => {
    response.results.forEach((entity) => {
        console.log(entity.id);
    });
});

Note: Node.js doesn't require the usage of a ngsi-proxy as you can create an HTTP endpoint easily (e.g. using express). Anyway, you can use it if you want, you only have to take into account that is better to directly provide the HTTP endpoint to reduce the overhead.

Using ngsijs from WireCloud widgets/operators

WireCloud already provides some components (widgets, operators and mashups) allowing NGSI connectivity. E.g.:

Anyway, WireCloud uses ngsijs as the binding for connecting to context brokers. If you need to create a new specific component you can take a look into the "3.2.1. Using Orion Context Broker" tutorial available at the FIWARE Academy.

ngsijs's People

Contributors

aarranz avatar fdelavega avatar dependabot[bot] avatar cblanco avatar fgalan avatar fisuda avatar rockneurotiko avatar

Stargazers

Javed Khan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.