MetaData REST API¶
This section shows the basic entity requests used in the REST API of the MetaData Repository. For a detail explanation, please look the ETSI spec (https://www.etsi.org/deliver/etsi_gs/CIM/001_099/004/01.01.02_60/gs_cim004v010102p.pdf).
Table of contents
Add entity¶
-
POST
/ngsi-ld/v1/entities/
¶ Add a new entity.
- Request Headers
Content-Type – application/ld+json
Example request:
$ curl --location --request POST 'http://{{broker-host}}/ngsi-ld/v1/entities/' \ --header 'Content-Type: application/ld+json' \ --data-raw '{ "@context":[ "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", { "Vehicle": "http://example.org/vehicle/Vehicle", "brandName": "http://example.org/vehicle/brandName", "speed": "http://example.org/vehicle/speed" } ], "id":"urn:ngsi-ld:Vehicle:TEST1", "type":"Vehicle", "brandName":{ "type":"Property", "value":"Mercedes" }, "speed":{ "type":"Property", "value":80 }, "location": { "type": "GeoProperty", "value": { "type": "Point", "coordinates": [ -1.1336517, 37.9894006 ] } } }'
- Status Codes
201 Created – Created
Obtain entities by type¶
-
GET
/ngsi-ld/v1/entities
¶ Retrieve a list of all the entities.
- Query Parameters
type (string) – entity type code as
http://example.org/vehicle/Vehicle
,http://www.w3.org/2003/01/geo/wgs84_pos%23Point
,indexing
, etc.
Example request:
$ curl --location --request GET 'http://{{broker-host}}/ngsi-ld/v1/entities/?type=http://example.org/vehicle/Vehicle'
import requests url = "http://metadata-repository-scorpiobroker.35.241.228.250.nip.io/ngsi-ld/v1/entities/?type=indexing" payload = {} headers= {} response = requests.request("GET", url, headers=headers, data = payload) print(response.text.encode('utf8'))
var request = require('request'); var options = { 'method': 'GET', 'url': 'http://metadata-repository-scorpiobroker.35.241.228.250.nip.io/ngsi-ld/v1/entities/?type=indexing', 'headers': { } }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
Example response:
[ { "id": "urn:ngsi-ld:Vehicle:TEST1", "type": "http://example.org/vehicle/Vehicle", "http://example.org/vehicle/brandName": { "type": "Property", "value": "Mercedes" }, "http://example.org/vehicle/speed": { "type": "Property", "value": 80 }, "location": { "type": "GeoProperty", "value": { "type": "Point", "coordinates": [ -1.1336517, 37.9894006 ] } }, "@context": [ "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld" ] } ]
- Response Headers
Content-Type – application/ld+json
- Status Codes
200 OK – no error
Obtain entity by id¶
-
GET
/ngsi-ld/v1/entities/
(str: get_id)¶ Retrieve an entity by identifier.
- Parameters
get_id (str) – get’s unique id
Example request:
$ curl --location --request GET 'http://{{broker-host}}/ngsi-ld/v1/entities/urn:ngsi-ld:Vehicle:TEST1'
Example response:
{ "id": "urn:ngsi-ld:Vehicle:TEST1", "type": "http://example.org/vehicle/Vehicle", "http://example.org/vehicle/brandName": { "type": "Property", "value": "Mercedes" }, "http://example.org/vehicle/speed": { "type": "Property", "value": 80 }, "location": { "type": "GeoProperty", "value": { "type": "Point", "coordinates": [ -1.1336517, 37.9894006 ] } }, "@context": [ "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld" ] }
- Response Headers
Content-Type – application/ld+json
- Status Codes
200 OK – no error
404 Not Found – not found
Update entity¶
-
PATCH
/ngsi-ld/v1/entities/
(str: patch)/attrs
¶ Update entity.
- Parameters
patch (str) – patch’s unique id
- Request Headers
Content-Type – application/ld+json
Example request:
$ curl --location --request PATCH 'http://{{broker-host}}/ngsi-ld/v1/entities/urn:ngsi-ld:Vehicle:TEST1/attrs' \ --header 'Content-Type: application/ld+json' \ --data-raw '{ "@context":[ "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", { "Vehicle": "http://example.org/vehicle/Vehicle", "brandName": "http://example.org/vehicle/brandName", "speed": "http://example.org/vehicle/speed" } ], "brandName":{ "type":"Property", "value":"Seat" }, "speed": { "type": "Property", "value": 5 } }'
- Status Codes
204 No Content – No content, no error
404 Not Found – not found
Delete entity¶
-
DELETE
/ngsi-ld/v1/entities/
(str: delete_id)¶ Remove an entity by identifier.
- Parameters
delete_id (str) – delete’s unique id
Example request:
$ curl --location --request DELETE 'http://{{broker-host}}/ngsi-ld/v1/entities/urn:ngsi-ld:Vehicle:TEST1'
- Status Codes
204 No Content – No content, no error
404 Not Found – not found