Skip to content

feat(fastify-rdf): add RDF content type parser for request bodies#187

Merged
ddeboer merged 3 commits intomainfrom
feat/fastify-rdf-parse
Mar 2, 2026
Merged

feat(fastify-rdf): add RDF content type parser for request bodies#187
ddeboer merged 3 commits intomainfrom
feat/fastify-rdf-parse

Conversation

@ddeboer
Copy link
Member

@ddeboer ddeboer commented Mar 2, 2026

Summary

The @lde/fastify-rdf plugin already handles RDF output (serialisation via sendRdf()); this adds the natural complement: RDF input (deserialisation via content type parsers).

  • Register Fastify content type parsers for all RDF formats supported by rdf-parse
  • Two ways to enable RDF body parsing into a DatasetCore (N3 Store):
    • Per-route: config: { parseRdf: true } on individual routes
    • Global: parseRdf: true on the plugin options — applies to all routes
  • Routes without either get JSON fallback for application/ld+json and 415 Unsupported Media Type for other RDF types
  • Add rdf-parse to dependencies; move n3 from devDependencies to dependencies
  • Augment Fastify's FastifyContextConfig with typed parseRdf property
  • Add 7 tests: Turtle, JSON-LD, N-Triples parsing, global parseRdf, JSON-LD fallback, 415 rejection, malformed body
  • Document both modes in README

Fix #185

Test plan

  • npx nx test fastify-rdf — 19 tests pass
  • npx nx lint fastify-rdf — no errors
  • npx nx typecheck fastify-rdf — no type errors
  • npx nx build fastify-rdf — builds successfully

ddeboer added 3 commits March 2, 2026 16:26
- Add `parseRdf` plugin option that registers Fastify content type
  parsers for all RDF formats supported by rdf-parse
- Routes opt in via `config: { parseRdf: true }`; the body is parsed
  into a DatasetCore (N3 Store)
- Routes without that config get JSON fallback for application/ld+json
  and 415 for other RDF types
- Add rdf-parse dependency; move n3 from devDependencies to dependencies
- Add tests for Turtle, JSON-LD, N-Triples parsing, fallback, 415, and
  malformed body handling
- Document the new option in README
…el option

- Remove `parseRdf` from `FastifyRdfOptions`; parsers are now always
  registered — the only knob is per-route `config: { parseRdf: true }`
- Remove redundant test for the removed plugin-level gate
- Update README to reflect the simplified API
- Re-add `parseRdf` to `FastifyRdfOptions` — when set, all routes get
  RDF body parsing without needing per-route config
- Per-route `config: { parseRdf: true }` still works for selective use
- Add test for plugin-level parseRdf behaviour
- Update README to document both modes
@ddeboer ddeboer merged commit b583fba into main Mar 2, 2026
2 checks passed
@ddeboer ddeboer deleted the feat/fastify-rdf-parse branch March 2, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RDF content type parser to fastify-rdf

1 participant