Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for introduction via CoRE Link Format #29

Merged
merged 5 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
});
});