@axonsdev/hateoas-siren
v0.1.0
Published
Siren media type support for `@axonsdev/hateoas-core`.
Downloads
21
Readme
@axonsdev/hateoas-siren
Siren media type support for @axonsdev/hateoas-core.
This package defines Siren TypeScript types and a parser that converts Siren entities into the core normalized hypermedia model.
Responsibilities
- Define Siren entity, link, action, field, and embedded entity types.
- Parse Siren responses into
HypermediaResourceModel. - Preserve the original Siren response in
raw. - Expose the Siren media type constant.
Main Exports
SIREN_MEDIA_TYPE
SirenParser
sirenParser()
SirenEntity
SirenEmbeddedEntity
SirenAction
SirenField
SirenLinkMedia Type
application/vnd.siren+jsonThe parser supports content types that include this media type.
Basic Usage
import { createHateoasClient } from '@axonsdev/hateoas-core';
import { fetchTransport } from '@axonsdev/hateoas-fetch';
import { sirenParser } from '@axonsdev/hateoas-siren';
const client = createHateoasClient({
transport: fetchTransport({ baseUrl: 'http://localhost:3000' }),
parsers: [sirenParser()],
});Mapping
Siren maps into the core model like this:
Siren class -> resource.classes
Siren properties -> resource.properties
Siren links -> resource.links
Siren actions -> resource.actions
Siren entities -> resource.entities
Original body -> resource.rawAction fields are mapped into HypermediaField:
name
type
title
value
required
optionsThe value field is useful for generic edit forms, where the API can provide the current value directly in the action descriptor.
Embedded Entities
Siren embedded entities become HypermediaEmbeddedEntity values.
Embedded entities are normalized recursively, including their own:
rel
classes
properties
links
actions
entities
rawExtending
If the API uses a different hypermedia format, implement HypermediaParser in a different package and register that parser with the core client.
This package should remain focused only on Siren.
