Skip to content

Commit

Permalink
Merge pull request #29 from JKRhb/well-known-core
Browse files Browse the repository at this point in the history
feat: add support for introduction via CoRE Link Format
  • Loading branch information
relu91 authored Oct 25, 2022
2 parents 5a9ce7e + 1bad31d commit 6e63c28
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and flexible. Currently, Zion supports the following features:
- [Introduction methods](https://w3c.github.io/wot-discovery/#introduction-mech) :
- DNS-SD
- Well-known URL
- CoRE Link Format and `/.well-known/core`
- Standard API:
- CRUD operations on the collection of TDs
- JSONPath queries compliant with IETF JSONPath standard [draft 5](https://datatracker.ietf.org/doc/html/draft-ietf-jsonpath-base#section-3.5.8)
Expand Down Expand Up @@ -113,7 +114,7 @@ services:
- [ ] Standard API
* [ ] XPath queries
* [ ] SPARQL queries supported with an external SPARQL endpoint
* [ ] CoRE introduction method
* [x] CoRE introduction method
- [ ] Experimental API
* [ ] GEO spatial queries
* [ ] User private TD collection CRUD
Expand Down
12 changes: 11 additions & 1 deletion src/introduction/well-known.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { FastifyReply } from 'fastify';
import { WellKnownService } from './well-known.service';

/**
* This controller is used to expose the Thing Description document.
* This controller is used to handle well-known URIs.
*
* It exposes the Thing Description document via `/.well-known/wot` and
* implements the CoRE Link Format introduction method via `/.well-known/core`.
*
* @see https://w3c.github.io/wot-discovery/#introduction-well-known
* @see https://w3c.github.io/wot-discovery/#introduction-core-rd-sec
*/
@ApiTags('Introduction')
@Controller('.well-known')
Expand All @@ -28,4 +32,10 @@ export class WellKnownController {
response.header('Content-length', `${size}`);
await response.send();
}

@Get('core')
@Header('Content-type', 'application/link-format')
public wellKnownCore() {
return '</wot>rt="wot.directory";ct=432';
}
}
24 changes: 24 additions & 0 deletions test/e2e/well-known.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ describe('/well-known', () => {
* @see https://w3c.github.io/wot-discovery/#introduction-well-known
*/
const SPECIFICATION_PATH = 'wot';
/**
* @see https://www.rfc-editor.org/rfc/rfc6690.html#section-7.1
*/
const WELL_KNOWN_CORE_PATH = 'core';
let axios: AxiosInstance;
let app: INestApplication;

Expand Down Expand Up @@ -67,4 +71,24 @@ describe('/well-known', () => {
});
});
});

describe(`/${WELL_KNOWN_CORE_PATH}`, () => {
describe('GET', () => {
it('should answer to well-known', async () => {
const { status } = await axios.get(`/.well-known/${WELL_KNOWN_CORE_PATH}`);
expect(status).toBe(200);
});

/**
* @see https://w3c.github.io/wot-discovery/#introduction-core-rd-sec
*/
it('should follow the specification', async () => {
const { status, headers, data } = await axios.get(`/.well-known/${WELL_KNOWN_CORE_PATH}`);

expect(status).toBe(200);
expect(data).toBe('</wot>rt="wot.directory";ct=432');
expect(headers['content-type']).toContain('application/link-format');
});
});
});
});

0 comments on commit 6e63c28

Please sign in to comment.