Skip to content

Commit cc99922

Browse files
committed
Amend responses.
1 parent 943ce21 commit cc99922

1 file changed

Lines changed: 118 additions & 3 deletions

File tree

README.md

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,43 @@ function readEntity(entityId, opts, headers = {}) {
341341
The equivalent cUrl statement can be seen below:
342342

343343
```console
344-
curl -G -X GET 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Building:store001/' \
344+
curl -G -X GET 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Building:store001' \
345345
-H 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
346346
-H 'Content-Type: application/json' \
347347
-d 'options=keyValues'
348348
```
349349

350+
And the response from the broker is:
351+
352+
```json
353+
{
354+
"id": "urn:ngsi-ld:Building:store001",
355+
"type": "Building",
356+
"category": {
357+
"vocab": "commercial"
358+
},
359+
"address": {
360+
"streetAddress": "Bornholmer Straße 65",
361+
"addressRegion": "Berlin",
362+
"addressLocality": "Prenzlauer Berg",
363+
"postalCode": "10439"
364+
},
365+
"location": {
366+
"type": "Point",
367+
"coordinates": [
368+
13.3986,
369+
52.5547
370+
]
371+
},
372+
"name": "Bösebrücke Einkauf",
373+
"furniture": [
374+
"urn:ngsi-ld:Shelf:unit001",
375+
"urn:ngsi-ld:Shelf:unit002",
376+
"urn:ngsi-ld:Shelf:unit003"
377+
]
378+
}
379+
```
380+
350381
## Aggregating and Traversing Linked Data
351382

352383
To display information at the till, it is necessary to discover information about the products found within a Store.
@@ -391,7 +422,20 @@ curl -G -X GET 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Building:s
391422
-H 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
392423
-H 'Content-Type: application/json' \
393424
-d 'options=keyValues' \
394-
-d 'attrs=furniture' \
425+
-d 'attrs=furniture'
426+
```
427+
And the response from the broker is:
428+
429+
```json
430+
{
431+
"id": "urn:ngsi-ld:Building:store001",
432+
"type": "Building",
433+
"furniture": [
434+
"urn:ngsi-ld:Shelf:unit001",
435+
"urn:ngsi-ld:Shelf:unit002",
436+
"urn:ngsi-ld:Shelf:unit003"
437+
]
438+
}
395439
```
396440

397441
The response is a JSON Object which includes a `furniture` attribute which can be manipulated further.
@@ -441,7 +485,30 @@ curl -G -X GET 'http://localhost:1026/ngsi-ld/v1/entities/' \
441485
```
442486

443487
The response is a JSON Array of **Shelf** entities which includes as `stocks` attribute which can be manipulated
444-
further. The code below extracts the IDs for later use.
488+
further.
489+
490+
```json
491+
[
492+
{
493+
"id": "urn:ngsi-ld:Shelf:unit001",
494+
"type": "Shelf",
495+
"numberOfItems": 15,
496+
"stocks": "urn:ngsi-ld:Product:001"
497+
},
498+
{
499+
"id": "urn:ngsi-ld:Shelf:unit002",
500+
"type": "Shelf",
501+
"numberOfItems": 15,
502+
"stocks": "urn:ngsi-ld:Product:003"
503+
},
504+
{
505+
"id": "urn:ngsi-ld:Shelf:unit003",
506+
"type": "Shelf",
507+
"numberOfItems": 15,
508+
"stocks": "urn:ngsi-ld:Product:004"
509+
}
510+
]
511+
```
445512

446513
```javascript
447514
const stockedProducts = [];
@@ -486,6 +553,29 @@ curl -G -X GET 'http://localhost:1026/ngsi-ld/v1/entities/' \
486553

487554
The response is a JSON Array of **Product** entities which are then displayed on screen.
488555

556+
```json
557+
[
558+
{
559+
"id": "urn:ngsi-ld:Product:001",
560+
"type": "Product",
561+
"price": 0.99,
562+
"name": "Apples"
563+
},
564+
{
565+
"id": "urn:ngsi-ld:Product:003",
566+
"type": "Product",
567+
"price": 14.99,
568+
"name": "Coconuts"
569+
},
570+
{
571+
"id": "urn:ngsi-ld:Product:004",
572+
"type": "Product",
573+
"price": 50,
574+
"name": "Melons"
575+
}
576+
]
577+
```
578+
489579
## Updating Linked Data
490580

491581
### Find a shelf stocking a product
@@ -520,6 +610,31 @@ curl -G -X GET 'http://localhost:1026/ngsi-ld/v1/entities/' \
520610
-d 'q=numberOfItems%3E0;locatedIn==%22urn:ngsi-ld:Building:store001%22;stocks==%22urn:ngsi-ld:Product:001%22'
521611
```
522612

613+
And the response from the broker is the following with nine shelves:
614+
615+
```json
616+
[
617+
{
618+
"id": "urn:ngsi-ld:Shelf:unit001",
619+
"type": "Shelf",
620+
"location": {
621+
"type": "Point",
622+
"coordinates": [
623+
13.398611,
624+
52.554699
625+
]
626+
},
627+
"maxCapacity": 50,
628+
"numberOfItems": 15,
629+
"name": "Corner Unit",
630+
"stocks": "urn:ngsi-ld:Product:001",
631+
"locatedIn": "urn:ngsi-ld:Building:store001"
632+
}
633+
634+
...etc
635+
]
636+
```
637+
523638
### Update the state of a shelf
524639

525640
To update an entity a PATCH request is made using the `id` of the **Shelf** returned in the previous request

0 commit comments

Comments
 (0)