GithubHelp home page GithubHelp logo

isabella232 / fiware-ngsi2-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from orange-opensource/fiware-ngsi2-api

0.0 0.0 0.0 237 KB

Fiware NGSI v2 API

License: Apache License 2.0

Java 100.00%

fiware-ngsi2-api's Introduction

FIWARE NGSI API

Build Status Coverity Scan Status Coverage Status Client Doc Server Doc Apache Version 2 Licence

This project is a Java library for the NGSI v2 API

This library was originally created for the Fiware-Cepheus project. A library implementing NGSI v1 API can be found at Orange-OpenSource/fiware-ngsi-api

What remains to be done:

  • Simplified Entity Representation.
  • Virtual Attribute.
  • NotifyContext.
  • NotifyContextAvailability.

Usage

Client

The client is based on Spring AsyncRestTemplate HTTP client.

Add the client library to your pom.xml:

<dependency>
    <groupId>com.orange.fiware</groupId>
    <artifactId>ngsi2-client</artifactId>
    <version>X.Y.Z</version>
</dependency>

Get an instance of NgsiClient and provide the AsyncRestTemplate (a default one or customized to your needs) and a base URL for the NGSIv2 server to target:

AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate();
String baseURL = "http://server.org/";
Ngsi2Client client = new Ngsi2Client(asyncRestTemplate, baseURL);

All requests return a ListenableFuture. You can therefore block to get the response or provide a callback:

// Synchronous
Entity entity = ngsiClient.getEntity("DC_S1-D41", "Room", Arrays.asList("temperature", "humidity")).get();

// Asynchronous
ngsiClient.getEntity("DC_S1-D41", "Room", Arrays.asList("temperature", "humidity")).addCallback(entity -> {
        /* handle entity */
    }, ex -> {
        /* handle error */
    });

Request returning a list of elements (entities, types, etc...) use a Paginated class that wraps the list of elements and return additional pagination information like offet, limit and total count of elements:

// List the first twenty types and count total types
Paginated<EntityType> result = ngsiClient.getEntityTypes(0, 20, true).get();

List<EntityType> types = result.getItems();
int total = result.getTotal();

Server

The library proposes an abstract class Ngsi2BaseController based on the Spring MVC framework to let you implement a NGSIv2 server easily.

Add the server library to your pom.xml:

<dependency>
    <groupId>com.orange.fiware</groupId>
    <artifactId>ngsi2-server</artifactId>
    <version>X.Y.Z</version>
</dependency>

Implement a new class based on the Ngsi2BaseController in your project and override methods you want to support :

@RestController
@RequestMapping("/v2/")
public class Ngsi2Controller extends Ngsi2BaseController {
    @Override
    protected void createEntity(Entity entity){
      /* implementation */
    }
}

License

This project is under the Apache License version 2.0

fiware-ngsi2-api's People

Contributors

marcc-orange avatar pascaleborscia 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.