Skip to content

Commit 1cd3f6a

Browse files
committed
Format README
1 parent 1374666 commit 1cd3f6a

1 file changed

Lines changed: 37 additions & 37 deletions

File tree

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ tutorial:
197197
networks:
198198
- default
199199
expose:
200-
- "3000"
200+
- '3000'
201201
ports:
202-
- "3000:3000"
202+
- '3000:3000'
203203
environment:
204-
- "DEBUG=tutorial:*"
205-
- "WEB_APP_PORT=3000"
206-
- "NGSI_VERSION=ngsi-ld"
207-
- "CONTEXT_BROKER=http://orion:1026/ngsi-ld/v1"
204+
- 'DEBUG=tutorial:*'
205+
- 'WEB_APP_PORT=3000'
206+
- 'NGSI_VERSION=ngsi-ld'
207+
- 'CONTEXT_BROKER=http://orion:1026/ngsi-ld/v1'
208208
```
209209
210210
The `tutorial` container is driven by environment variables as shown:
@@ -264,7 +264,7 @@ define location of the data models JSON-LD context as
264264
`https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld`.
265265

266266
```javascript
267-
const ngsiLD = require("../../lib/ngsi-ld");
267+
const ngsiLD = require('../../lib/ngsi-ld');
268268
269269
const LinkHeader =
270270
'<https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json">';
@@ -280,11 +280,11 @@ necessary HTTP call in an asynchronous fashion:
280280
async function displayStore(req, res) {
281281
const store = await ngsiLD.readEntity(
282282
req.params.storeId,
283-
{ options: "keyValues" },
283+
{ options: 'keyValues' },
284284
ngsiLD.setHeaders(req.session.access_token, LinkHeader)
285285
);
286286
287-
return res.render("store", { title: store.name, store });
287+
return res.render('store', { title: store.name, store });
288288
}
289289
```
290290

@@ -300,13 +300,13 @@ OAuth2 security.
300300
function setHeaders(accessToken, link, contentType) {
301301
const headers = {};
302302
if (accessToken) {
303-
headers["X-Auth-Token"] = accessToken;
303+
headers['X-Auth-Token'] = accessToken;
304304
}
305305
if (link) {
306306
headers.Link = link;
307307
}
308308
if (contentType) {
309-
headers["Content-Type"] = contentType || "application/ld+json";
309+
headers['Content-Type'] = contentType || 'application/ld+json';
310310
}
311311
return headers;
312312
}
@@ -316,13 +316,13 @@ Within the `lib/ngsi-ld.js` library file, the `BASE_PATH` defines the location o
316316
data entity is simply a wrapper around an asynchronous HTTP GET request passing the appropriate headers
317317

318318
```javascript
319-
const BASE_PATH = process.env.CONTEXT_BROKER || "http://localhost:1026/ngsi-ld/v1";
319+
const BASE_PATH = process.env.CONTEXT_BROKER || 'http://localhost:1026/ngsi-ld/v1';
320320
321321
function readEntity(entityId, opts, headers = {}) {
322322
return request({
323323
qs: opts,
324-
url: BASE_PATH + "/entities/" + entityId,
325-
method: "GET",
324+
url: BASE_PATH + '/entities/' + entityId,
325+
method: 'GET',
326326
headers,
327327
json: true
328328
});
@@ -368,8 +368,8 @@ parameter.
368368
const building = await ngsiLD.readEntity(
369369
req.params.storeId,
370370
{
371-
options: "keyValues",
372-
attrs: "furniture"
371+
options: 'keyValues',
372+
attrs: 'furniture'
373373
},
374374
ngsiLD.setHeaders(req.session.access_token, LinkHeader)
375375
);
@@ -395,10 +395,10 @@ parameter. The `id` is just a comma separated list taken from the request above.
395395
```javascript
396396
let productsList = await ngsiLD.listEntities(
397397
{
398-
type: "Shelf",
399-
options: "keyValues",
400-
attrs: "stocks,numberOfItems",
401-
id: building.furniture.join(",")
398+
type: 'Shelf',
399+
options: 'keyValues',
400+
attrs: 'stocks,numberOfItems',
401+
id: building.furniture.join(',')
402402
},
403403
ngsiLD.setHeaders(req.session.access_token, LinkHeader)
404404
);
@@ -410,8 +410,8 @@ let productsList = await ngsiLD.listEntities(
410410
function listEntities(opts, headers = {}) {
411411
return request({
412412
qs: opts,
413-
url: BASE_PATH + "/entities",
414-
method: "GET",
413+
url: BASE_PATH + '/entities',
414+
method: 'GET',
415415
headers,
416416
json: true
417417
});
@@ -453,10 +453,10 @@ using the `id` parameter. The `id` is just a comma separated list taken from the
453453
```javascript
454454
let productsInStore = await ngsiLD.listEntities(
455455
{
456-
type: "Product",
457-
options: "keyValues",
458-
attrs: "name,price",
459-
id: stockedProducts.join(",")
456+
type: 'Product',
457+
options: 'keyValues',
458+
attrs: 'name,price',
459+
id: stockedProducts.join(',')
460460
},
461461
headers
462462
);
@@ -489,9 +489,9 @@ _relationships_ with both **Building** and **Product**.
489489
```javascript
490490
const shelf = await ngsiLD.listEntities(
491491
{
492-
type: "Shelf",
493-
options: "keyValues",
494-
attrs: "stocks,numberOfItems",
492+
type: 'Shelf',
493+
options: 'keyValues',
494+
attrs: 'stocks,numberOfItems',
495495
q: 'numberOfItems>0;locatedIn=="' + req.body.storeId + '";stocks=="' + req.body.productId + '"',
496496
limit: 1
497497
},
@@ -519,7 +519,7 @@ To update an entity a PATCH request is made using the `id` of the **Shelf** retu
519519
const count = shelf[0].numberOfItems - 1;
520520
await ngsiLD.updateAttribute(
521521
shelf[0].id,
522-
{ numberOfItems: { type: "Property", value: count } },
522+
{ numberOfItems: { type: 'Property', value: count } },
523523
ngsiLD.setHeaders(req.session.access_token, LinkHeader)
524524
);
525525
```
@@ -529,8 +529,8 @@ The asynchronous PATCH request is found in the `updateAttribute()` function with
529529
```javascript
530530
function updateAttribute(entityId, body, headers = {}) {
531531
return request({
532-
url: BASE_PATH + "/entities/" + entityId + "/attrs",
533-
method: "PATCH",
532+
url: BASE_PATH + '/entities/' + entityId + '/attrs',
533+
method: 'PATCH',
534534
body,
535535
headers,
536536
json: true
@@ -727,8 +727,8 @@ response to retrieve the data in a fully converted fashion for local use.
727727
JSON-LD libraries already exist to do this work.
728728

729729
```javascript
730-
const coreContext = require("./jsonld-context/ngsi-ld.json");
731-
const japaneseContext = require("./jsonld-context/japanese.json");
730+
const coreContext = require('./jsonld-context/ngsi-ld.json');
731+
const japaneseContext = require('./jsonld-context/japanese.json');
732732
733733
function translateRequest(req, res) {
734734
request({
@@ -739,10 +739,10 @@ function translateRequest(req, res) {
739739
json: true
740740
})
741741
.then(async function (cbResponse) {
742-
cbResponse["@context"] = coreContext;
742+
cbResponse['@context'] = coreContext;
743743
const expanded = await jsonld.expand(cbResponse);
744744
const compacted = await jsonld.compact(expanded, japaneseContext);
745-
delete compacted["@context"];
745+
delete compacted['@context'];
746746
return res.send(compacted);
747747
})
748748
.catch(function (err) {
@@ -794,7 +794,7 @@ payload before sending data to the context broker.
794794

795795
#### :arrow_forward: Video: JSON-LD Compaction & Expansion
796796

797-
[![](https://fiware.github.io/tutorials.Step-by-Step/img/video-logo.png)](https://www.youtube.com/watch?v=Tm3fD89dqRE "JSON-LD Compaction & Expansion")
797+
[![](https://fiware.github.io/tutorials.Step-by-Step/img/video-logo.png)](https://www.youtube.com/watch?v=Tm3fD89dqRE 'JSON-LD Compaction & Expansion')
798798

799799
Click on the image above to watch a video JSON-LD expansion and compaction with reference to the `@context`.
800800

0 commit comments

Comments
 (0)